#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 mkstemp(char *);
int /*<<< orphan*/ printf(char *, char *, int);
int /*<<< orphan*/ unlink(char *);
int get_temp_fd() {
  char fname[128] = "/tmp/outXXXXXX";
  int fd = mkstemp(fname);
  unlink(fname);
  printf("create temp file %s with fd %d\n", fname, fd);
  return fd;
}


x86 assembly (clang, -O0):
<get_temp_fd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
lea    -0x80(%rbp),%rdi
lea    0xeaa(%rip),%rsi
mov    $0x80,%edx
call   1050 <memcpy@plt>
lea    -0x80(%rbp),%rdi
call   1060 <mkstemp@plt>
mov    %eax,-0x84(%rbp)
lea    -0x80(%rbp),%rdi
call   1030 <unlink@plt>
lea    -0x80(%rbp),%rsi
mov    -0x84(%rbp),%edx
lea    0xef7(%rip),%rdi
call   1040 <printf@plt>
mov    -0x84(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_temp_fd>:
push   %rbp
push   %rbx
sub    $0x88,%rsp
movaps 0xf30(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xf14(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xef8(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xedc(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xec0(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xea4(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe88(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe6c(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1050 <mkstemp@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <unlink@plt>
lea    0xecc(%rip),%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1040 <printf@plt>
mov    %ebp,%eax
add    $0x88,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@__const.get_temp_fd.fname = [128 x i8] c"/tmp/outXXXXXX\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [32 x i8] c"create temp file %s with fd %d\0A\00"
define i32 @get_temp_fd() {
%1 = alloca [128 x i8]
%2 = alloca i32
%3 = bitcast [128 x i8]* %1 to i8*
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%5 = call i32 @mkstemp(i8* %4)
store i32 %5, i32* %2
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%7 = call i32 @unlink(i8* %6)
%8 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%9 = load i32, i32* %2
%10 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %8, i32 %9)
%11 = load i32, i32* %2
ret i32 %11
}

LLVM IR (-O2):
@__const.get_temp_fd.fname = [128 x i8] c"/tmp/outXXXXXX\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [32 x i8] c"create temp file %s with fd %d\0A\00"
define i32 @get_temp_fd() {
%1 = alloca [128 x i8]
%2 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%3 = call i32 @mkstemp(i8* %2)
%4 = call i32 @unlink(i8* %2)
%5 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %2, i32 %3)
ret i32 %3
}