#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);
int /*<<< orphan*/ creat(char *, int /*<<< orphan*/);
int getpid();
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ 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\n", getpid());
  creat(filename, 0);
  unlink(filename);
  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)
movl   $0x3,-0x34(%rbp)
cmpl   $0x40,-0x34(%rbp)
jge    118d <main+0x3d>
mov    -0x34(%rbp),%edi
call   1050 <close@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    116d <main+0x1d>
lea    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%edx
lea    0xe57(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
call   1060 <creat@plt>
lea    -0x30(%rbp),%rdi
call   1030 <unlink@plt>
xor    %eax,%eax
add    $0x40,%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    1160 <main+0x10>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe83(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %eax,%edx
call   1070 <sprintf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <creat@plt>
mov    %rbx,%rdi
call   1030 <unlink@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/tmp/file.%d\0A\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 3, i32* %7
br label %8
8: ; preds = %14, %2
%9 = load i32, i32* %7
%10 = icmp slt i32 %9, 64
br i1 %10, label %11, label %17
11: ; preds = %8
%12 = load i32, i32* %7
%13 = call i32 @close(i32 %12)
br label %14
14: ; preds = %11
%15 = load i32, i32* %7
%16 = add nsw i32 %15, 1
store i32 %16, i32* %7
br label %8
17: ; preds = %8
%18 = getelementptr inbounds [24 x i8], [24 x i8]* %6, i64 0, i64 0
%19 = call i32 (...) @getpid()
%20 = call i32 @sprintf(i8* %18, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = getelementptr inbounds [24 x i8], [24 x i8]* %6, i64 0, i64 0
%22 = call i32 @creat(i8* %21, i32 0)
%23 = getelementptr inbounds [24 x i8], [24 x i8]* %6, i64 0, i64 0
%24 = call i32 @unlink(i8* %23)
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"/tmp/file.%d\0A\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 ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = call i32 @creat(i8* %4, i32 0)
%14 = call i32 @unlink(i8* %4)
ret i32 0
}