#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*/ bug();
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ puts(char *);
int read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  char buf[10];
  int bytes_read = 0;
  memset(buf, 0, 10);
  bytes_read = read(0, buf, 10);
  if (!bytes_read)
    return 1;
  if (!strcmp(buf, "pwn"))
    bug();
  else
    puts("works!");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
lea    -0x1a(%rbp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1050 <memset@plt>
lea    -0x1a(%rbp),%rsi
xor    %edi,%edi
mov    $0xa,%edx
call   1060 <read@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jne    11a6 <main+0x56>
movl   $0x1,-0x4(%rbp)
jmp    11de <main+0x8e>
lea    -0x1a(%rbp),%rdi
lea    0xe4f(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    11cb <main+0x7b>
mov    $0x0,%al
call   1040 <bug@plt>
jmp    11d7 <main+0x87>
lea    0xe32(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0x6(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1050 <memset@plt>
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0xa,%edx
call   1060 <read@plt>
test   %eax,%eax
je     1186 <main+0x46>
cmpl   $0x6e7770,0x6(%rsp)
je     118d <main+0x4d>
lea    0xe87(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
jmp    1196 <main+0x56>
mov    $0x1,%ebx
jmp    1196 <main+0x56>
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <bug@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [4 x i8] c"pwn\00"
@.str.1 = [7 x i8] c"works!\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [10 x i8]
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
%8 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%9 = call i32 @memset(i8* %8, i32 0, i32 10)
%10 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%11 = call i32 @read(i32 0, i8* %10, i32 10)
store i32 %11, i32* %7
%12 = load i32, i32* %7
%13 = icmp ne i32 %12, 0
br i1 %13, label %15, label %14
14: ; preds = %2
store i32 1, i32* %3
br label %24
15: ; preds = %2
%16 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%17 = call i32 @strcmp(i8* %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%18 = icmp ne i32 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %15
%20 = call i32 (...) @bug()
br label %23
21: ; preds = %15
%22 = call i32 @puts(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %21, %19
store i32 0, i32* %3
br label %24
24: ; preds = %23, %14
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
@.str = [4 x i8] c"pwn\00"
@.str.1 = [7 x i8] c"works!\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [10 x i8]
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%5 = call i32 @memset(i8* %4, i32 0, i32 10)
%6 = call i32 @read(i32 0, i8* %4, i32 10)
%7 = icmp eq i32 %6, 0
br i1 %7, label %15, label %8
8: ; preds = %2
%9 = call i32 @bcmp(i8* dereferenceable(4) %4, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 4)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = call i32 (...) @bug()
br label %15
13: ; preds = %8
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %11, %13, %2
%16 = phi i32 [ 1, %2 ], [ 0, %13 ], [ 0, %11 ]
ret i32 %16
}