#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 /*<<< orphan*/);
int main(int argc, char **argv) {
  if (argc != 2) {
    printf("You need two arguments for this.\n");
    exit(0);
  }
  setreuid(1000, 0);
  if (access(argv[1], R_OK) == 0) {
    setreuid(0, 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,%edi
xor    %esi,%esi
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    1239 <main+0xc9>
xor    %esi,%esi
mov    %esi,%edi
call   1060 <setreuid@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe36(%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     1234 <main+0xc4>
lea    -0xe0(%rbp),%rsi
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11f8 <main+0x88>
jmp    1245 <main+0xd5>
lea    0xde8(%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
xor    %esi,%esi
call   1050 <setreuid@plt>
mov    0x8(%rbx),%rdi
mov    0x2e53(%rip),%rax
mov    (%rax),%esi
call   1060 <access@plt>
test   %rax,%rax
je     11a7 <main+0x47>
lea    0xe62(%rip),%rdi
call   1030 <puts@plt>
jmp    11fd <main+0x9d>
xor    %edi,%edi
xor    %esi,%esi
call   1050 <setreuid@plt>
mov    0x8(%rbx),%rdi
lea    0xe45(%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
nopl   0x0(%rax,%rax,1)
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 0)
%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 %36
21: ; preds = %13
%22 = call i32 @setreuid(i32 0, i32 0)
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32* @fopen(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %26, i32** %7
br label %27
27: ; preds = %32, %21
%28 = getelementptr inbounds [200 x i8], [200 x i8]* %6, i64 0, i64 0
%29 = load i32*, i32** %7
%30 = call i64 @fgets(i8* %28, i32 200, i32* %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = getelementptr inbounds [200 x i8], [200 x i8]* %6, i64 0, i64 0
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %33)
br label %27
35: ; preds = %27
br label %38
36: ; preds = %13
%37 = call i32 @puts(i8* getelementptr inbounds ([89 x i8], [89 x i8]* @.str.3, i64 0, i64 0))
br label %38
38: ; preds = %36, %35
%39 = load i32, i32* %3
ret i32 %39
}

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 0)
%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 %27
15: ; preds = %8
%16 = tail call i32 @setreuid(i32 0, i32 0)
%17 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 0
%18 = load i8*, i8** %10
%19 = tail call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%20 = call i64 @fgets(i8* %17, i32 200, i32* %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %15, %22
%23 = call i32 @puts(i8* %17)
%24 = call i64 @fgets(i8* %17, i32 200, i32* %19)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %22
26: ; preds = %22, %15
br label %29
27: ; preds = %8
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([89 x i8], [89 x i8]* @.str.3, i64 0, i64 0))
br label %29
29: ; preds = %27, %26
ret i32 0
}