#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 /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ err_sys(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sleep(int);
scalar_t__ unlink(char *);
int main(void) {
  if (open("test_link", O_RDWR) < 0) {
    err_sys("open error");
  }
  if (unlink("test_link") < 0) {
    err_sys("unlink error");
  }
  printf("file unlinked\n");
  sleep(15);
  printf("done\n");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
lea    0xe81(%rip),%rdi
call   1060 <open@plt>
cmp    $0x0,%rax
jge    119a <main+0x3a>
lea    0xe75(%rip),%rdi
call   1040 <err_sys@plt>
lea    0xe5f(%rip),%rdi
call   1030 <unlink@plt>
cmp    $0x0,%rax
jge    11bc <main+0x5c>
lea    0xe5e(%rip),%rdi
call   1040 <err_sys@plt>
lea    0xe5f(%rip),%rdi
call   1050 <printf@plt>
mov    $0xf,%edi
call   1080 <sleep@plt>
lea    0xe58(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
lea    0xe8f(%rip),%rdi
call   1060 <open@plt>
test   %rax,%rax
jns    1187 <main+0x27>
lea    0xe88(%rip),%rdi
call   1050 <err_sys@plt>
lea    0xe72(%rip),%rdi
call   1030 <unlink@plt>
test   %rax,%rax
jns    11a4 <main+0x44>
lea    0xe76(%rip),%rdi
call   1050 <err_sys@plt>
lea    0xe77(%rip),%rdi
call   1040 <puts@plt>
mov    $0xf,%edi
call   1080 <sleep@plt>
lea    0xe6f(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"test_link\00"
@O_RDWR = global i32 0
@.str.1 = [11 x i8] c"open error\00"
@.str.2 = [13 x i8] c"unlink error\00"
@.str.3 = [15 x i8] c"file unlinked\0A\00"
@.str.4 = [6 x i8] c"done\0A\00"
define i32 @main() {
%1 = alloca i32
store i32 0, i32* %1
%2 = load i32, i32* @O_RDWR
%3 = call i64 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = icmp slt i64 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = call i32 @err_sys(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %7
7: ; preds = %5, %0
%8 = call i64 @unlink(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = call i32 @err_sys(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %12
12: ; preds = %10, %7
%13 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%14 = call i32 @sleep(i32 15)
%15 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%16 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [10 x i8] c"test_link\00"
@O_RDWR = global i32 0
@.str.1 = [11 x i8] c"open error\00"
@.str.2 = [13 x i8] c"unlink error\00"
@str = [14 x i8] c"file unlinked\00"
@str.5 = [5 x i8] c"done\00"
define i32 @main() {
%1 = load i32, i32* @O_RDWR
%2 = tail call i64 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp slt i64 %2, 0
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = tail call i32 @err_sys(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %6
6: ; preds = %4, %0
%7 = tail call i64 @unlink(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 @err_sys(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %11
11: ; preds = %9, %6
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%13 = tail call i32 @sleep(i32 15)
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.5, i64 0, i64 0))
%15 = tail call i32 @exit(i32 0)
unreachable
}