#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 EOF;
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int link(char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int scanf(char *, char *);
int /*<<< orphan*/ stdout;
int symlink(char *, char *);
int main() {
  char p[10];
  printf("Give me a path: \n");
  int n = scanf("%s", p);
  fflush(stdout);
  printf("%s", p);
  if (n != EOF) {
    printf("read: %s\n", p);
    int slinked = symlink("nuevo.sym", p);
    if (slinked == 0) {
      int hlinked = link("nuevo.hard", p);
      if (hlinked == 0)
        printf("done");
      else
        perror("link");
    } else
      perror("symlink");
  } else
    perror("scanf");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0xe(%rbp),%rsi
lea    0xe8a(%rip),%rdi
call   1060 <scanf@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
lea    -0xe(%rbp),%rsi
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
mov    0x2e2e(%rip),%rcx
cmp    (%rcx),%eax
je     1243 <main+0xe3>
lea    -0xe(%rbp),%rsi
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0xe(%rbp),%rsi
lea    0xe40(%rip),%rdi
call   1040 <symlink@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    1232 <main+0xd2>
lea    -0xe(%rbp),%rsi
lea    0xe2d(%rip),%rdi
call   1080 <link@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1221 <main+0xc1>
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    122d <main+0xcd>
lea    0xe14(%rip),%rdi
call   1070 <perror@plt>
jmp    123e <main+0xde>
lea    0xe00(%rip),%rdi
call   1070 <perror@plt>
jmp    124f <main+0xef>
lea    0xdf7(%rip),%rdi
call   1070 <perror@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xeb6(%rip),%rdi
call   1030 <puts@plt>
lea    0xe75(%rip),%rbx
lea    0x6(%rsp),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <scanf@plt>
mov    %eax,%ebp
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e29(%rip),%rax
cmp    (%rax),%ebp
je     121a <main+0xaa>
lea    0xe39(%rip),%rdi
lea    0x6(%rsp),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe2d(%rip),%rdi
mov    %rbx,%rsi
call   1050 <symlink@plt>
test   %eax,%eax
jne    1223 <main+0xb3>
lea    0xe24(%rip),%rdi
lea    0x6(%rsp),%rsi
call   1090 <link@plt>
test   %eax,%eax
jne    122c <main+0xbc>
lea    0xe1a(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe0e(%rip),%rdi
jmp    1233 <main+0xc3>
lea    0xdfd(%rip),%rdi
jmp    1233 <main+0xc3>
lea    0xdf7(%rip),%rdi
call   1080 <perror@plt>
jmp    120f <main+0x9f>

LLVM IR (-O0):
@.str = [18 x i8] c"Give me a path: \0A\00"
@.str.1 = [3 x i8] c"%s\00"
@stdout = global i32 0
@EOF = global i32 0
@.str.2 = [10 x i8] c"read: %s\0A\00"
@.str.3 = [10 x i8] c"nuevo.sym\00"
@.str.4 = [11 x i8] c"nuevo.hard\00"
@.str.5 = [5 x i8] c"done\00"
@.str.6 = [5 x i8] c"link\00"
@.str.7 = [8 x i8] c"symlink\00"
@.str.8 = [6 x i8] c"scanf\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %7)
store i32 %8, i32* %3
%9 = load i32, i32* @stdout
%10 = call i32 @fflush(i32 %9)
%11 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = load i32, i32* %3
%14 = load i32, i32* @EOF
%15 = icmp ne i32 %13, %14
br i1 %15, label %16, label %36
16: ; preds = %0
%17 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %17)
%19 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%20 = call i32 @symlink(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %19)
store i32 %20, i32* %4
%21 = load i32, i32* %4
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %33
23: ; preds = %16
%24 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%25 = call i32 @link(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %24)
store i32 %25, i32* %5
%26 = load i32, i32* %5
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %23
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %32
30: ; preds = %23
%31 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
br label %32
32: ; preds = %30, %28
br label %35
33: ; preds = %16
%34 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
br label %35
35: ; preds = %33, %32
br label %38
36: ; preds = %0
%37 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
br label %38
38: ; preds = %36, %35
%39 = load i32, i32* %1
ret i32 %39
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%s\00"
@stdout = global i32 0
@EOF = global i32 0
@.str.2 = [10 x i8] c"read: %s\0A\00"
@.str.3 = [10 x i8] c"nuevo.sym\00"
@.str.4 = [11 x i8] c"nuevo.hard\00"
@.str.5 = [5 x i8] c"done\00"
@.str.6 = [5 x i8] c"link\00"
@.str.7 = [8 x i8] c"symlink\00"
@.str.8 = [6 x i8] c"scanf\00"
@str = [17 x i8] c"Give me a path: \00"
define i32 @main() {
%1 = alloca [10 x i8]
%2 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%5 = load i32, i32* @stdout
%6 = call i32 @fflush(i32 %5)
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%8 = load i32, i32* @EOF
%9 = icmp eq i32 %4, %8
br i1 %9, label %23, label %10
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%12 = call i32 @symlink(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %2)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %21
14: ; preds = %10
%15 = call i32 @link(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %2)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %25
19: ; preds = %14
%20 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
br label %25
21: ; preds = %10
%22 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
br label %25
23: ; preds = %0
%24 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
br label %25
25: ; preds = %21, %19, %17, %23
ret i32 0
}