#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 O_CREAT;
int O_RDWR;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ open(char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
scalar_t__ unlink(char *);
int main(int argc, char const *argv[]) {
  if (open("tempfile", O_CREAT | O_RDWR) < 0) {
    fprintf(stderr, "open error\n");
    exit(1);
  }
  if (unlink("tempfile") < 0) {
    fprintf(stderr, "unlink error\n");
    exit(1);
  }
  printf("file unlinked\n");
  sleep(15);
  printf("done\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e7b(%rip),%rax
mov    (%rax),%esi
mov    0x2e5a(%rip),%rax
or     (%rax),%esi
lea    0xe71(%rip),%rdi
call   1060 <open@plt>
cmp    $0x0,%rax
jge    11bd <main+0x5d>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
lea    0xe5b(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xe3c(%rip),%rdi
call   1030 <unlink@plt>
cmp    $0x0,%rax
jge    11f2 <main+0x92>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
lea    0xe32(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xe2a(%rip),%rdi
call   1040 <printf@plt>
mov    $0xf,%edi
call   1080 <sleep@plt>
lea    0xe23(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    0x2e90(%rip),%rax
mov    0x2e71(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe86(%rip),%rdi
call   1060 <open@plt>
test   %rax,%rax
js     11bb <main+0x5b>
lea    0xe75(%rip),%rdi
call   1030 <unlink@plt>
test   %rax,%rax
js     11cd <main+0x6d>
lea    0xe87(%rip),%rdi
call   1040 <puts@plt>
mov    $0xf,%edi
call   1080 <sleep@plt>
lea    0xe7f(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
lea    0xe3e(%rip),%rsi
jmp    11dd <main+0x7d>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
lea    0xe38(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

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

LLVM IR (-O2):
@.str = [9 x i8] c"tempfile\00"
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@stderr = global i32 0
@.str.1 = [12 x i8] c"open error\0A\00"
@.str.2 = [14 x i8] c"unlink error\0A\00"
@str = [14 x i8] c"file unlinked\00"
@str.5 = [5 x i8] c"done\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @O_CREAT
%4 = load i32, i32* @O_RDWR
%5 = or i32 %4, %3
%6 = tail call i64 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = tail call i64 @unlink(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %12
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %12
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%21 = tail call i32 @sleep(i32 15)
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.5, i64 0, i64 0))
ret i32 0
}