#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
char *malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *compose_add_challenge(char *u1, char *u2, int dist, int newTurn,
                            int key) {
  char *execStr = malloc(200);
  strcpy(execStr, "UPDATE game_data SET key=\"");
  char c[20];
  sprintf(c, "%d", key);
  strcat(execStr, c);
  strcat(execStr, "\", dist=\"");
  sprintf(c, "%d", dist);
  strcat(execStr, c);
  strcat(execStr, "\", turn=\"");
  sprintf(c, "%d", newTurn);
  strcat(execStr, c);
  strcat(execStr, "\", last=\"");
  strcat(execStr, c);
  strcat(execStr, "\" WHERE u1=\"");
  strcat(execStr, u1);
  strcat(execStr, "\" and u2=\"");
  strcat(execStr, u2);
  strcat(execStr, "\";");
  return execStr;
}


x86 assembly (clang, -O0):
<compose_add_challenge>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    $0xc8,%edi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe8d(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x40(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0xe95(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x28(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x28(%rbp),%rdi
lea    0xe7b(%rip),%rsi
call   1050 <strcat@plt>
lea    -0x40(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe65(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x28(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x28(%rbp),%rdi
lea    0xe55(%rip),%rsi
call   1050 <strcat@plt>
lea    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%edx
lea    0xe35(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x28(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x28(%rbp),%rdi
lea    0xe2f(%rip),%rsi
call   1050 <strcat@plt>
mov    -0x28(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x28(%rbp),%rdi
lea    0xe1c(%rip),%rsi
call   1050 <strcat@plt>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x28(%rbp),%rdi
lea    0xe0c(%rip),%rsi
call   1050 <strcat@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x28(%rbp),%rdi
lea    0xdfa(%rip),%rsi
call   1050 <strcat@plt>
mov    -0x28(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compose_add_challenge>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8d,%r15d
mov    %ecx,%r12d
mov    %edx,%r13d
mov    %rsi,0x8(%rsp)
mov    %rdi,(%rsp)
mov    $0xc8,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
lea    0xe8c(%rip),%rsi
mov    %rax,%rdi
call   1030 <strcpy@plt>
lea    0xe98(%rip),%r14
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1060 <sprintf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1050 <strcat@plt>
lea    0xe76(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcat@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
mov    %r13d,%edx
call   1060 <sprintf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1050 <strcat@plt>
lea    0xe58(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcat@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
mov    %r12d,%edx
call   1060 <sprintf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1050 <strcat@plt>
lea    0xe3a(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcat@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1050 <strcat@plt>
lea    0xe2a(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcat@plt>
mov    %rbx,%rdi
mov    (%rsp),%rsi
call   1050 <strcat@plt>
lea    0xe1c(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcat@plt>
mov    %rbx,%rdi
mov    0x8(%rsp),%rsi
call   1050 <strcat@plt>
lea    0xe0b(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcat@plt>
mov    %rbx,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"UPDATE game_data SET key=\22\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [10 x i8] c"\22, dist=\22\00"
@.str.3 = [10 x i8] c"\22, turn=\22\00"
@.str.4 = [10 x i8] c"\22, last=\22\00"
@.str.5 = [13 x i8] c"\22 WHERE u1=\22\00"
@.str.6 = [11 x i8] c"\22 and u2=\22\00"
@.str.7 = [3 x i8] c"\22;\00"
define i8* @compose_add_challenge(i8* %0, i8* %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca [20 x i8]
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%13 = call i8* @malloc(i32 200)
store i8* %13, i8** %11
%14 = load i8*, i8** %11
%15 = call i32 @strcpy(i8* %14, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%16 = getelementptr inbounds [20 x i8], [20 x i8]* %12, i64 0, i64 0
%17 = load i32, i32* %10
%18 = call i32 @sprintf(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %17)
%19 = load i8*, i8** %11
%20 = getelementptr inbounds [20 x i8], [20 x i8]* %12, i64 0, i64 0
%21 = call i32 @strcat(i8* %19, i8* %20)
%22 = load i8*, i8** %11
%23 = call i32 @strcat(i8* %22, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%24 = getelementptr inbounds [20 x i8], [20 x i8]* %12, i64 0, i64 0
%25 = load i32, i32* %8
%26 = call i32 @sprintf(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %25)
%27 = load i8*, i8** %11
%28 = getelementptr inbounds [20 x i8], [20 x i8]* %12, i64 0, i64 0
%29 = call i32 @strcat(i8* %27, i8* %28)
%30 = load i8*, i8** %11
%31 = call i32 @strcat(i8* %30, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%32 = getelementptr inbounds [20 x i8], [20 x i8]* %12, i64 0, i64 0
%33 = load i32, i32* %9
%34 = call i32 @sprintf(i8* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %33)
%35 = load i8*, i8** %11
%36 = getelementptr inbounds [20 x i8], [20 x i8]* %12, i64 0, i64 0
%37 = call i32 @strcat(i8* %35, i8* %36)
%38 = load i8*, i8** %11
%39 = call i32 @strcat(i8* %38, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%40 = load i8*, i8** %11
%41 = getelementptr inbounds [20 x i8], [20 x i8]* %12, i64 0, i64 0
%42 = call i32 @strcat(i8* %40, i8* %41)
%43 = load i8*, i8** %11
%44 = call i32 @strcat(i8* %43, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%45 = load i8*, i8** %11
%46 = load i8*, i8** %6
%47 = call i32 @strcat(i8* %45, i8* %46)
%48 = load i8*, i8** %11
%49 = call i32 @strcat(i8* %48, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%50 = load i8*, i8** %11
%51 = load i8*, i8** %7
%52 = call i32 @strcat(i8* %50, i8* %51)
%53 = load i8*, i8** %11
%54 = call i32 @strcat(i8* %53, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%55 = load i8*, i8** %11
ret i8* %55
}

LLVM IR (-O2):
@.str = [27 x i8] c"UPDATE game_data SET key=\22\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [10 x i8] c"\22, dist=\22\00"
@.str.3 = [10 x i8] c"\22, turn=\22\00"
@.str.4 = [10 x i8] c"\22, last=\22\00"
@.str.5 = [13 x i8] c"\22 WHERE u1=\22\00"
@.str.6 = [11 x i8] c"\22 and u2=\22\00"
@.str.7 = [3 x i8] c"\22;\00"
define i8* @compose_add_challenge(i8* %0, i8* %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca [20 x i8]
%7 = tail call dereferenceable_or_null(200) i8* @malloc(i32 200)
%8 = tail call i32 @strcpy(i8* %7, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%10 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %4)
%11 = call i32 @strcat(i8* %7, i8* %9)
%12 = call i32 @strcat(i8* %7, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%13 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %2)
%14 = call i32 @strcat(i8* %7, i8* %9)
%15 = call i32 @strcat(i8* %7, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%16 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %3)
%17 = call i32 @strcat(i8* %7, i8* %9)
%18 = call i32 @strcat(i8* %7, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%19 = call i32 @strcat(i8* %7, i8* %9)
%20 = call i32 @strcat(i8* %7, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%21 = call i32 @strcat(i8* %7, i8* %0)
%22 = call i32 @strcat(i8* %7, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%23 = call i32 @strcat(i8* %7, i8* %1)
%24 = call i32 @strcat(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
ret i8* %7
}