#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*/ close(int);
long creat(char *, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int getpid();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
long unlink(char *);
int main(int argc, char **argv) {
  char filename[24];
  {
    int i;
    for (i = 3; i < 64; i++)
      close(i);
  };
  sprintf(filename, "/tmp/file.%d", getpid());
  ({
    long res = creat(filename, 0);
    if (res < 0) {
      perror("creat(filename, 0)");
      exit(1);
    };
    res;
  });
  ({
    long res = unlink(filename);
    if (res < 0) {
      perror("unlink(filename)");
      exit(1);
    };
    res;
  });
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x3,-0x34(%rbp)
cmpl   $0x40,-0x34(%rbp)
jge    11ad <main+0x3d>
mov    -0x34(%rbp),%edi
call   1050 <close@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    118d <main+0x1d>
lea    -0x30(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x60(%rbp),%rdi
mov    %eax,%edx
lea    0xe37(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
call   1070 <creat@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jge    11fe <main+0x8e>
lea    0xe1e(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
lea    -0x30(%rbp),%rdi
call   1030 <unlink@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jge    1234 <main+0xc4>
lea    0xdfb(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x50(%rbp),%rax
mov    %rax,-0x58(%rbp)
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
mov    $0x3,%ebx
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1050 <close@plt>
add    $0x1,%ebx
cmp    $0x40,%ebx
jne    1180 <main+0x10>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe63(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %eax,%edx
call   1080 <sprintf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <creat@plt>
test   %rax,%rax
js     11ce <main+0x5e>
mov    %rsp,%rdi
call   1030 <unlink@plt>
test   %rax,%rax
js     11d7 <main+0x67>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret
lea    0xe38(%rip),%rdi
jmp    11de <main+0x6e>
lea    0xe42(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"/tmp/file.%d\00"
@.str.1 = [19 x i8] c"creat(filename, 0)\00"
@.str.2 = [17 x i8] c"unlink(filename)\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [24 x i8]
%7 = alloca i32
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 3, i32* %7
br label %12
12: ; preds = %18, %2
%13 = load i32, i32* %7
%14 = icmp slt i32 %13, 64
br i1 %14, label %15, label %21
15: ; preds = %12
%16 = load i32, i32* %7
%17 = call i32 @close(i32 %16)
br label %18
18: ; preds = %15
%19 = load i32, i32* %7
%20 = add nsw i32 %19, 1
store i32 %20, i32* %7
br label %12
21: ; preds = %12
%22 = getelementptr inbounds [24 x i8], [24 x i8]* %6, i64 0, i64 0
%23 = call i32 (...) @getpid()
%24 = call i32 @sprintf(i8* %22, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %23)
%25 = getelementptr inbounds [24 x i8], [24 x i8]* %6, i64 0, i64 0
%26 = call i64 @creat(i8* %25, i32 0)
store i64 %26, i64* %8
%27 = load i64, i64* %8
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %21
%30 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %21
%33 = load i64, i64* %8
store i64 %33, i64* %9
%34 = load i64, i64* %9
%35 = getelementptr inbounds [24 x i8], [24 x i8]* %6, i64 0, i64 0
%36 = call i64 @unlink(i8* %35)
store i64 %36, i64* %10
%37 = load i64, i64* %10
%38 = icmp slt i64 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %32
%40 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %32
%43 = load i64, i64* %10
store i64 %43, i64* %11
%44 = load i64, i64* %11
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"/tmp/file.%d\00"
@.str.1 = [19 x i8] c"creat(filename, 0)\00"
@.str.2 = [17 x i8] c"unlink(filename)\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [24 x i8]
%4 = getelementptr inbounds [24 x i8], [24 x i8]* %3, i64 0, i64 0
br label %5
5: ; preds = %2, %5
%6 = phi i32 [ 3, %2 ], [ %8, %5 ]
%7 = tail call i32 @close(i32 %6)
%8 = add nuw nsw i32 %6, 1
%9 = icmp eq i32 %8, 64
br i1 %9, label %10, label %5
10: ; preds = %5
%11 = tail call i32 (...) @getpid()
%12 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = call i64 @creat(i8* %4, i32 0)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %10
%19 = call i64 @unlink(i8* %4)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %18
ret i32 0
}