#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 O_TRUNC;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ S_IRWXU;
int lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ my_err(char *, int);
int open(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ read(int, char *, int);
scalar_t__ unlink(char *);
scalar_t__ write(int, char *, int);
int main(int argc, char *argv[]) {
  int fd;
  char buf[32];
  if ((fd = open("temp", O_RDWR | O_CREAT | O_TRUNC, S_IRWXU)) < 0) {
    my_err("open", 35);
  }
  if (unlink("temp") < 0) {
    my_err("unlink", 38);
  }
  printf("file unlinked\n");
  if (write(fd, "temp", 5) < 0) {
    my_err("write", 43);
  }
  if ((lseek(fd, 0, SEEK_SET)) == -1) {
    my_err("lseek", 46);
  }
  if (read(fd, buf, 5) < 0) {
    my_err("read", 49);
  }
  printf("%s\n", buf);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e43(%rip),%rax
mov    (%rax),%esi
mov    0x2e62(%rip),%rax
or     (%rax),%esi
mov    0x2e51(%rip),%rax
or     (%rax),%esi
mov    0x2e30(%rip),%rax
mov    (%rax),%edx
lea    0xe4f(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11d3 <main+0x63>
lea    0xe3c(%rip),%rdi
mov    $0x23,%esi
call   1090 <my_err@plt>
lea    0xe26(%rip),%rdi
call   1030 <unlink@plt>
cmp    $0x0,%rax
jge    11fa <main+0x8a>
lea    0xe1a(%rip),%rdi
mov    $0x26,%esi
call   1090 <my_err@plt>
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
lea    0xdee(%rip),%rsi
mov    $0x5,%edx
call   1040 <write@plt>
cmp    $0x0,%rax
jge    1237 <main+0xc7>
lea    0xdf3(%rip),%rdi
mov    $0x2b,%esi
call   1090 <my_err@plt>
mov    -0x14(%rbp),%edi
mov    0x2d7f(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <lseek@plt>
cmp    $0xffffffff,%eax
jne    1264 <main+0xf4>
lea    0xdcc(%rip),%rdi
mov    $0x2e,%esi
call   1090 <my_err@plt>
mov    -0x14(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x5,%edx
call   1070 <read@plt>
cmp    $0x0,%rax
jge    1290 <main+0x120>
lea    0xda6(%rip),%rdi
mov    $0x31,%esi
call   1090 <my_err@plt>
lea    -0x40(%rbp),%rsi
lea    0xd96(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
mov    0x2e54(%rip),%rax
mov    0x2e75(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e62(%rip),%rax
or     (%rax),%esi
mov    0x2e41(%rip),%rax
mov    (%rax),%edx
lea    0xe60(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    11bc <main+0x4c>
lea    0xe53(%rip),%rdi
mov    $0x23,%esi
call   1090 <my_err@plt>
lea    0xe3d(%rip),%rdi
call   1030 <unlink@plt>
test   %rax,%rax
jns    11de <main+0x6e>
lea    0xe36(%rip),%rdi
mov    $0x26,%esi
call   1090 <my_err@plt>
lea    0xe3d(%rip),%rdi
call   1040 <puts@plt>
lea    0xe0f(%rip),%rsi
mov    %ebx,%edi
mov    $0x5,%edx
call   1050 <write@plt>
test   %rax,%rax
jns    1213 <main+0xa3>
lea    0xe08(%rip),%rdi
mov    $0x2b,%esi
call   1090 <my_err@plt>
mov    0x2da6(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
xor    %esi,%esi
call   1060 <lseek@plt>
cmp    $0xffffffff,%eax
jne    123b <main+0xcb>
lea    0xde6(%rip),%rdi
mov    $0x2e,%esi
call   1090 <my_err@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x5,%edx
call   1070 <read@plt>
test   %rax,%rax
jns    1260 <main+0xf0>
lea    0xdc7(%rip),%rdi
mov    $0x31,%esi
call   1090 <my_err@plt>
mov    %rsp,%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"temp\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRWXU = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [7 x i8] c"unlink\00"
@.str.3 = [15 x i8] c"file unlinked\0A\00"
@.str.4 = [6 x i8] c"write\00"
@SEEK_SET = global i32 0
@.str.5 = [6 x i8] c"lseek\00"
@.str.6 = [5 x i8] c"read\00"
@.str.7 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [32 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* @O_RDWR
%9 = load i32, i32* @O_CREAT
%10 = or i32 %8, %9
%11 = load i32, i32* @O_TRUNC
%12 = or i32 %10, %11
%13 = load i32, i32* @S_IRWXU
%14 = call i32 @open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %13)
store i32 %14, i32* %6
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 @my_err(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 35)
br label %18
18: ; preds = %16, %2
%19 = call i64 @unlink(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i32 @my_err(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 38)
br label %23
23: ; preds = %21, %18
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%25 = load i32, i32* %6
%26 = call i64 @write(i32 %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 5)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %23
%29 = call i32 @my_err(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 43)
br label %30
30: ; preds = %28, %23
%31 = load i32, i32* %6
%32 = load i32, i32* @SEEK_SET
%33 = call i32 @lseek(i32 %31, i32 0, i32 %32)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %37
35: ; preds = %30
%36 = call i32 @my_err(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 46)
br label %37
37: ; preds = %35, %30
%38 = load i32, i32* %6
%39 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%40 = call i64 @read(i32 %38, i8* %39, i32 5)
%41 = icmp slt i64 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %37
%43 = call i32 @my_err(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i32 49)
br label %44
44: ; preds = %42, %37
%45 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* %45)
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"temp\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRWXU = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [7 x i8] c"unlink\00"
@.str.4 = [6 x i8] c"write\00"
@SEEK_SET = global i32 0
@.str.5 = [6 x i8] c"lseek\00"
@.str.6 = [5 x i8] c"read\00"
@str = [14 x i8] c"file unlinked\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [32 x i8]
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @O_RDWR
%6 = load i32, i32* @O_CREAT
%7 = or i32 %6, %5
%8 = load i32, i32* @O_TRUNC
%9 = or i32 %7, %8
%10 = load i32, i32* @S_IRWXU
%11 = tail call i32 @open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %10)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = tail call i32 @my_err(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 35)
br label %15
15: ; preds = %13, %2
%16 = tail call i64 @unlink(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = tail call i32 @my_err(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 38)
br label %20
20: ; preds = %18, %15
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%22 = tail call i64 @write(i32 %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 5)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = tail call i32 @my_err(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 43)
br label %26
26: ; preds = %24, %20
%27 = load i32, i32* @SEEK_SET
%28 = tail call i32 @lseek(i32 %11, i32 0, i32 %27)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = tail call i32 @my_err(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 46)
br label %32
32: ; preds = %30, %26
%33 = call i64 @read(i32 %11, i8* %4, i32 5)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %32
%36 = tail call i32 @my_err(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i32 49)
br label %37
37: ; preds = %35, %32
%38 = call i32 @puts(i8* %4)
ret i32 0
}