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

/* Variables and functions */
int /*<<< orphan*/ R_OK;
scalar_t__ access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ setreuid(int, int);
int main(int argc, char **argv) {
  if (argc != 2) {
    printf("You need two arguments for this.\n");
    exit(0);
  }
  setreuid(1000, 1000);
  if (access(argv[1], R_OK) == 0) {
    char found[200];
    FILE *target = fopen(argv[1], "r");
    while (fgets(found, sizeof(found), target)) {
      printf("%s\n", found);
    }
  } else {
    puts("Oh that's right, you can't grab the ladder. We should experiment on "
         "how to improve that.");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11a8 <main+0x38>
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    $0x3e8,%esi
mov    %esi,%edi
call   1060 <setreuid@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e1d(%rip),%rax
mov    (%rax),%esi
call   1070 <access@plt>
cmp    $0x0,%rax
jne    1230 <main+0xc0>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe3f(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0xe8(%rbp)
lea    -0xe0(%rbp),%rdi
mov    -0xe8(%rbp),%rdx
mov    $0xc8,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     122b <main+0xbb>
lea    -0xe0(%rbp),%rsi
lea    0xe05(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11ef <main+0x7f>
jmp    123c <main+0xcc>
lea    0xdf1(%rip),%rdi
call   1030 <puts@plt>
mov    -0x4(%rbp),%eax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0xc8,%rsp
cmp    $0x2,%edi
jne    120a <main+0xaa>
mov    %rsi,%rbx
mov    $0x3e8,%edi
mov    $0x3e8,%esi
call   1050 <setreuid@plt>
mov    0x8(%rbx),%rdi
mov    0x2e50(%rip),%rax
mov    (%rax),%esi
call   1060 <access@plt>
test   %rax,%rax
je     11aa <main+0x4a>
lea    0xe5f(%rip),%rdi
call   1030 <puts@plt>
jmp    11fd <main+0x9d>
mov    0x8(%rbx),%rdi
lea    0xe4b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0xc8,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11fd <main+0x9d>
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    $0xc8,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
jne    11e0 <main+0x80>
xor    %eax,%eax
add    $0xc8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe4a(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [34 x i8] c"You need two arguments for this.\0A\00"
@R_OK = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [89 x i8] c"Oh that's right, you can't grab the ladder. We should experiment on how to improve that.\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [200 x i8]
%7 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 0)
unreachable
13: ; preds = %2
%14 = call i32 @setreuid(i32 1000, i32 1000)
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = load i32, i32* @R_OK
%19 = call i64 @access(i8* %17, i32 %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %35
21: ; preds = %13
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %25, i32** %7
br label %26
26: ; preds = %31, %21
%27 = getelementptr inbounds [200 x i8], [200 x i8]* %6, i64 0, i64 0
%28 = load i32*, i32** %7
%29 = call i64 @fgets(i8* %27, i32 200, i32* %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %26
%32 = getelementptr inbounds [200 x i8], [200 x i8]* %6, i64 0, i64 0
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %32)
br label %26
34: ; preds = %26
br label %37
35: ; preds = %13
%36 = call i32 @puts(i8* getelementptr inbounds ([89 x i8], [89 x i8]* @.str.3, i64 0, i64 0))
br label %37
37: ; preds = %35, %34
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
@R_OK = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [89 x i8] c"Oh that's right, you can't grab the ladder. We should experiment on how to improve that.\00"
@str = [33 x i8] c"You need two arguments for this.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [200 x i8]
%4 = icmp eq i32 %0, 2
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 0)
unreachable
8: ; preds = %2
%9 = tail call i32 @setreuid(i32 1000, i32 1000)
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = load i32, i32* @R_OK
%13 = tail call i64 @access(i8* %11, i32 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %26
15: ; preds = %8
%16 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 0
%17 = load i8*, i8** %10
%18 = tail call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%19 = call i64 @fgets(i8* %16, i32 200, i32* %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %25, label %21
21: ; preds = %15, %21
%22 = call i32 @puts(i8* %16)
%23 = call i64 @fgets(i8* %16, i32 200, i32* %18)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %21
25: ; preds = %21, %15
br label %28
26: ; preds = %8
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([89 x i8], [89 x i8]* @.str.3, i64 0, i64 0))
br label %28
28: ; preds = %26, %25
ret i32 0
}