#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 dummy;
};

/* Variables and functions */
scalar_t__ link(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ stat(char *, struct stat *);
int main(int argc, char *argv[]) {
  struct stat st;
  if (argc != 3) {
    printf("ln: source dest\n");
    return 1;
  }
  if (stat(argv[1], &st) < 0) {
    printf("ln: stat error %s\n", argv[1]);
    return 1;
  }
  if (link(argv[1], argv[2]) < 0) {
    printf("ln: %s %s failed\n", argv[1], argv[2]);
  }
}


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)
cmpl   $0x3,-0x8(%rbp)
je     116a <main+0x3a>
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11e4 <main+0xb4>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0x0,%rax
jge    11a7 <main+0x77>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11e4 <main+0xb4>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1050 <link@plt>
cmp    $0x0,%rax
jge    11e4 <main+0xb4>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
cmp    $0x3,%edi
jne    118d <main+0x4d>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
mov    %rsp,%rsi
call   1050 <stat@plt>
mov    0x8(%rbx),%rcx
test   %rax,%rax
js     119b <main+0x5b>
mov    0x10(%rbx),%rsi
mov    %rcx,%rdi
call   1060 <link@plt>
xor    %ebp,%ebp
test   %rax,%rax
jns    11b1 <main+0x71>
mov    0x8(%rbx),%rsi
mov    0x10(%rbx),%rdx
lea    0xe91(%rip),%rdi
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11b1 <main+0x71>
lea    0xe91(%rip),%rdi
call   1030 <puts@plt>
jmp    11ac <main+0x6c>
lea    0xe5e(%rip),%rdi
mov    %rcx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [17 x i8] c"ln: source dest\0A\00"
@.str.1 = [19 x i8] c"ln: stat error %s\0A\00"
@.str.2 = [18 x i8] c"ln: %s %s failed\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.stat
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 3
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %39
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i64 @stat(i8* %14, %struct.stat* %6)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %11
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %20)
store i32 1, i32* %3
br label %39
22: ; preds = %11
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = call i64 @link(i8* %25, i8* %28)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %39
31: ; preds = %22
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 2
%37 = load i8*, i8** %36
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %34, i8* %37)
br label %39
39: ; preds = %9, %17, %31, %22
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str.1 = [19 x i8] c"ln: stat error %s\0A\00"
@.str.2 = [18 x i8] c"ln: %s %s failed\0A\00"
@str = [16 x i8] c"ln: source dest\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = icmp eq i32 %0, 3
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
br label %25
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = call i64 @stat(i8* %10, %struct.stat* %3)
%12 = icmp slt i64 %11, 0
%13 = load i8*, i8** %9
br i1 %12, label %14, label %16
14: ; preds = %8
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %13)
br label %25
16: ; preds = %8
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = call i64 @link(i8* %13, i8* %18)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %16
%22 = load i8*, i8** %9
%23 = load i8*, i8** %17
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %22, i8* %23)
br label %25
25: ; preds = %16, %21, %14, %6
%26 = phi i32 [ 1, %6 ], [ 1, %14 ], [ 0, %21 ], [ 0, %16 ]
ret i32 %26
}