#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 */
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ snprintf(char *, int, char *);
int strlen(char *);
int /*<<< orphan*/ system(char *);
int main(int argc, char **argv) {
  int i = 1;
  char buffer[64];
  snprintf(buffer, sizeof buffer, argv[1]);
  buffer[sizeof(buffer) - 1] = 0;
  printf("Change i's value from 1 -> 500. ");
  if (i == 500) {
    printf("GOOD\n");
    system("/bin/sh");
  }
  printf("No way...let me give you a hint!\n");
  printf("buffer : [%s] (%d)\n", buffer, strlen(buffer));
  printf("i = %d (%p)\n", i, &i);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
mov    $0x40,%esi
call   1060 <snprintf@plt>
movb   $0x0,-0x21(%rbp)
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x1f4,-0x14(%rbp)
jne    11ac <main+0x6c>
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe80(%rip),%rdi
call   1040 <system@plt>
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x60(%rbp),%rax
mov    %rax,-0x68(%rbp)
lea    -0x60(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x68(%rbp),%rsi
mov    %eax,%edx
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xe7c(%rip),%rdi
lea    -0x14(%rbp),%rdx
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x50,%rsp
movl   $0x1,0xc(%rsp)
mov    0x8(%rsi),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x40,%esi
call   1060 <snprintf@plt>
movb   $0x0,0x4f(%rsp)
lea    0xe91(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xec5(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0xe90(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe91(%rip),%rdi
lea    0xc(%rsp),%rdx
mov    $0x1,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [33 x i8] c"Change i's value from 1 -> 500. \00"
@.str.1 = [6 x i8] c"GOOD\0A\00"
@.str.2 = [8 x i8] c"/bin/sh\00"
@.str.3 = [34 x i8] c"No way...let me give you a hint!\0A\00"
@.str.4 = [20 x i8] c"buffer : [%s] (%d)\0A\00"
@.str.5 = [13 x i8] c"i = %d (%p)\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [64 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %6
%8 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 1
%11 = load i8*, i8** %10
%12 = call i32 @snprintf(i8* %8, i32 64, i8* %11)
%13 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 63
store i8 0, i8* %13
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* %6
%16 = icmp eq i32 %15, 500
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @system(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %20
20: ; preds = %17, %2
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
%22 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%23 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%24 = call i32 @strlen(i8* %23)
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %22, i32 %24)
%26 = load i32, i32* %6
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 %26, i32* %6)
ret i32 0
}

LLVM IR (-O2):
@.str = [33 x i8] c"Change i's value from 1 -> 500. \00"
@.str.4 = [20 x i8] c"buffer : [%s] (%d)\0A\00"
@.str.5 = [13 x i8] c"i = %d (%p)\0A\00"
@str = [33 x i8] c"No way...let me give you a hint!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca [64 x i8]
%5 = bitcast i32* %3 to i8*
store i32 1, i32* %3
%6 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = call i32 @snprintf(i8* %6, i32 64, i8* %8)
%10 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 63
store i8 0, i8* %10
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
%13 = call i32 @strlen(i8* %6)
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %6, i32 %13)
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 1, i32* %3)
ret i32 0
}