#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 */
struct stat {
  int /*<<< orphan*/ st_mode;
};
typedef int /*<<< orphan*/ handle;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ S_ISLNK(int /*<<< orphan*/);
scalar_t__ S_ISREG(int /*<<< orphan*/);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int lstat(char *, struct stat *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ scanf(char *, char **);
scalar_t__ strcmp(char *, char *);
int main() {
  char handle[500];
  scanf("%10s", &handle);
  if ((strcmp(handle, "exit")) == 0) {
    puts("Not so fast, you have a looong way down.");
    exit(0);
  }
  FILE *hope;
  hope = fopen(handle, "r");
  if (hope == NULL) {
    perror("error");
    puts("You really don't have any, do you?");
    exit(0);
  }
  struct stat check;
  int success = lstat(handle, &check);
  if (S_ISREG(check.st_mode)) {
    fgets(handle, sizeof(handle), hope);
    printf("%s\n", handle);
  }
  if (S_ISLNK(check.st_mode)) {
    puts("No symbolic link attacks.");
    exit(0);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x200(%rbp),%rsi
lea    0xe30(%rip),%rdi
call   10a0 <scanf@plt>
lea    -0x200(%rbp),%rdi
lea    0xe22(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    1205 <main+0x55>
lea    0xe11(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
lea    -0x200(%rbp),%rdi
lea    0xe24(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x208(%rbp)
cmpq   $0x0,-0x208(%rbp)
jne    124c <main+0x9c>
lea    0xdff(%rip),%rdi
call   10c0 <perror@plt>
lea    0xdf9(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
lea    -0x200(%rbp),%rdi
lea    -0x210(%rbp),%rsi
call   1060 <lstat@plt>
mov    %eax,-0x214(%rbp)
mov    -0x210(%rbp),%edi
call   1090 <S_ISREG@plt>
cmp    $0x0,%rax
je     12a5 <main+0xf5>
lea    -0x200(%rbp),%rdi
mov    -0x208(%rbp),%rdx
mov    $0x1f4,%esi
call   1070 <fgets@plt>
lea    -0x200(%rbp),%rsi
lea    0xdbc(%rip),%rdi
call   1050 <printf@plt>
mov    -0x210(%rbp),%edi
call   1030 <S_ISLNK@plt>
cmp    $0x0,%rax
je     12cd <main+0x11d>
lea    0xd9f(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x210,%rsp
lea    0xe3e(%rip),%rdi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
call   10a0 <scanf@plt>
lea    0xe2f(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1259 <main+0xa9>
lea    0xe4d(%rip),%rsi
lea    0x10(%rsp),%rdi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1262 <main+0xb2>
mov    %rax,%rbx
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1060 <lstat@plt>
mov    0x8(%rsp),%ebp
mov    %ebp,%edi
call   1090 <S_ISREG@plt>
test   %rax,%rax
je     123f <main+0x8f>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0x1f4,%esi
mov    %rbx,%rdx
call   1070 <fgets@plt>
lea    0xe25(%rip),%rdi
mov    %r14,%rsi
call   1050 <printf@plt>
mov    %ebp,%edi
call   1030 <S_ISLNK@plt>
test   %rax,%rax
jne    1277 <main+0xc7>
xor    %eax,%eax
add    $0x210,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xdaa(%rip),%rdi
jmp    127e <main+0xce>
lea    0xdca(%rip),%rdi
call   10c0 <perror@plt>
lea    0xdc4(%rip),%rdi
jmp    127e <main+0xce>
lea    0xde2(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [5 x i8] c"%10s\00"
@.str.1 = [5 x i8] c"exit\00"
@.str.2 = [41 x i8] c"Not so fast, you have a looong way down.\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [6 x i8] c"error\00"
@.str.5 = [35 x i8] c"You really don't have any, do you?\00"
@.str.6 = [4 x i8] c"%s\0A\00"
@.str.7 = [26 x i8] c"No symbolic link attacks.\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [500 x i8]
%3 = alloca i32*
%4 = alloca %struct.stat
%5 = alloca i32
store i32 0, i32* %1
%6 = bitcast [500 x i8]* %2 to i8**
%7 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %6)
%8 = getelementptr inbounds [500 x i8], [500 x i8]* %2, i64 0, i64 0
%9 = call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %0
%12 = call i32 @puts(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0))
%13 = call i32 @exit(i32 0)
unreachable
14: ; preds = %0
%15 = getelementptr inbounds [500 x i8], [500 x i8]* %2, i64 0, i64 0
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %16, i32** %3
%17 = load i32*, i32** %3
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %23
19: ; preds = %14
%20 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%21 = call i32 @puts(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0))
%22 = call i32 @exit(i32 0)
unreachable
23: ; preds = %14
%24 = getelementptr inbounds [500 x i8], [500 x i8]* %2, i64 0, i64 0
%25 = call i32 @lstat(i8* %24, %struct.stat* %4)
store i32 %25, i32* %5
%26 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%27 = load i32, i32* %26
%28 = call i64 @S_ISREG(i32 %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %36
30: ; preds = %23
%31 = getelementptr inbounds [500 x i8], [500 x i8]* %2, i64 0, i64 0
%32 = load i32*, i32** %3
%33 = call i32 @fgets(i8* %31, i32 500, i32* %32)
%34 = getelementptr inbounds [500 x i8], [500 x i8]* %2, i64 0, i64 0
%35 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %34)
br label %36
36: ; preds = %30, %23
%37 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%38 = load i32, i32* %37
%39 = call i64 @S_ISLNK(i32 %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %36
%42 = call i32 @puts(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0))
%43 = call i32 @exit(i32 0)
unreachable
44: ; preds = %36
%45 = load i32, i32* %1
ret i32 %45
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [5 x i8] c"%10s\00"
@.str.1 = [5 x i8] c"exit\00"
@.str.2 = [41 x i8] c"Not so fast, you have a looong way down.\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [6 x i8] c"error\00"
@.str.5 = [35 x i8] c"You really don't have any, do you?\00"
@.str.6 = [4 x i8] c"%s\0A\00"
@.str.7 = [26 x i8] c"No symbolic link attacks.\00"
define i32 @main() {
%1 = alloca [500 x i8]
%2 = alloca %struct.stat
%3 = getelementptr inbounds [500 x i8], [500 x i8]* %1, i64 0, i64 0
%4 = bitcast [500 x i8]* %1 to i8**
%5 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %4)
%6 = call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 @exit(i32 0)
unreachable
11: ; preds = %0
%12 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0))
%17 = call i32 @exit(i32 0)
unreachable
18: ; preds = %11
%19 = bitcast %struct.stat* %2 to i8*
%20 = call i32 @lstat(i8* %3, %struct.stat* %2)
%21 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%22 = load i32, i32* %21
%23 = call i64 @S_ISREG(i32 %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %18
%26 = call i32 @fgets(i8* %3, i32 500, i32* %12)
%27 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %3)
br label %28
28: ; preds = %25, %18
%29 = call i64 @S_ISLNK(i32 %22)
%30 = icmp eq i64 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %28
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0))
%33 = call i32 @exit(i32 0)
unreachable
34: ; preds = %28
ret i32 0
}