#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*/ fprintf(int /*<<< orphan*/, char *, char *, int);
int mkstemp(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ unlink(char *);
int get_temp_fd() {
  char fname[128] = "/tmp/inXXXXXX";
  int fd = mkstemp(fname);
  unlink(fname);
  fprintf(stderr, "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>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
lea    -0x80(%rbp),%rdx
mov    -0x84(%rbp),%ecx
lea    0xeee(%rip),%rsi
call   1040 <fprintf@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>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
lea    0xec3(%rip),%rsi
mov    %rbx,%rdx
mov    %ebp,%ecx
call   1040 <fprintf@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/inXXXXXX\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\00"
@stderr = global i32 0
@.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 = load i32, i32* @stderr
%9 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%10 = load i32, i32* %2
%11 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %9, i32 %10)
%12 = load i32, i32* %2
ret i32 %12
}

LLVM IR (-O2):
@__const.get_temp_fd.fname = [128 x i8] c"/tmp/inXXXXXX\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\00"
@stderr = global i32 0
@.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 = load i32, i32* @stderr
%6 = call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %2, i32 %3)
ret i32 %3
}