#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 */
int /*<<< orphan*/ exploit();
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(int *, char *, int);
int /*<<< orphan*/ memset(int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ strcmp(int *, char *);
int func() {
  int *flag;
  char *cmp = "y";
  char name[20] = {0};
  flag = (int *)malloc(4);
  memset(flag, 0, 4);
  memcpy(flag, "n", 1);
  scanf("%s", name);
  printf(name);
  if (!strcmp(flag, cmp)) {
    exploit();
  }
  return 1;
}


x86 assembly (clang, -O0):
<func>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xe81(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1040 <memset@plt>
mov    $0x4,%edi
call   1070 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    -0x8(%rbp),%rdi
lea    0xe46(%rip),%rsi
mov    $0x1,%edx
call   1060 <memcpy@plt>
lea    -0x30(%rbp),%rsi
lea    0xe33(%rip),%rdi
call   1080 <scanf@plt>
lea    -0x30(%rbp),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11fc <func+0x8c>
mov    $0x0,%al
call   1090 <exploit@plt>
mov    $0x1,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<func>:
push   %r14
push   %rbx
sub    $0x18,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movl   $0x0,0x10(%rsp)
mov    $0x4,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
lea    0xe59(%rip),%rsi
mov    %rbx,%rdi
mov    $0x1,%edx
call   1060 <memcpy@plt>
lea    0xe47(%rip),%rdi
mov    %rsp,%r14
mov    %r14,%rsi
call   1080 <scanf@plt>
mov    %r14,%rdi
call   1030 <printf@plt>
lea    0xe29(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
jne    11ea <func+0x7a>
xor    %eax,%eax
call   1090 <exploit@plt>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"y\00"
@.str.1 = [2 x i8] c"n\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @func() {
%1 = alloca i32*
%2 = alloca i8*
%3 = alloca [20 x i8]
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %2
%4 = bitcast [20 x i8]* %3 to i8*
%5 = call i64 @malloc(i32 4)
%6 = inttoptr i64 %5 to i32*
store i32* %6, i32** %1
%7 = load i32*, i32** %1
%8 = call i32 @memset(i32* %7, i32 0, i32 4)
%9 = load i32*, i32** %1
%10 = call i32 @memcpy(i32* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%11 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %11)
%13 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%14 = call i32 @printf(i8* %13)
%15 = load i32*, i32** %1
%16 = load i8*, i8** %2
%17 = call i32 @strcmp(i32* %15, i8* %16)
%18 = icmp ne i32 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %0
%20 = call i32 (...) @exploit()
br label %21
21: ; preds = %19, %0
ret i32 1
}

LLVM IR (-O2):
@.str = [2 x i8] c"y\00"
@.str.1 = [2 x i8] c"n\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @func() {
%1 = alloca [20 x i8]
%2 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%3 = tail call i64 @malloc(i32 4)
%4 = inttoptr i64 %3 to i32*
%5 = tail call i32 @memset(i32* %4, i32 0, i32 4)
%6 = tail call i32 @memcpy(i32* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%8 = call i32 @printf(i8* %2)
%9 = call i32 @strcmp(i32* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 (...) @exploit()
br label %13
13: ; preds = %11, %0
ret i32 1
}