#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 PATH_MAX;
int /*<<< orphan*/ err(int, char *, char const *, char *);
int mkstemp(char *);
int /*<<< orphan*/ snprintf(char *, int, char *);
int /*<<< orphan*/ unlink(char *);
void tempfile(const char *test, int *fdp) {
  char path[PATH_MAX];
  int fd;
  snprintf(path, PATH_MAX, "/tmp/unix_passfd.XXXXXXXXXXXXXXX");
  fd = mkstemp(path);
  if (fd < 0)
    err(-1, "%s: mkstemp(%s)", test, path);
  (void)unlink(path);
  *fdp = fd;
}


x86 assembly (clang, -O0):
<tempfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e99(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x30(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
mov    0x2e6d(%rip),%rax
mov    (%rax),%esi
lea    0xe74(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x30(%rbp),%rdi
call   1060 <mkstemp@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    11c0 <tempfile+0x80>
mov    -0x30(%rbp),%rcx
mov    -0x8(%rbp),%rdx
mov    $0xffffffff,%edi
lea    0xe66(%rip),%rsi
call   1050 <err@plt>
mov    -0x30(%rbp),%rdi
call   1030 <unlink@plt>
mov    -0x24(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tempfile>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    0x2e98(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rbx
mov    %rsi,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe8b(%rip),%rdx
mov    %rbx,%rdi
call   1040 <snprintf@plt>
mov    %rbx,%rdi
call   1060 <mkstemp@plt>
mov    %eax,%r12d
test   %eax,%eax
jns    11a3 <tempfile+0x63>
lea    0xe8e(%rip),%rsi
mov    $0xffffffff,%edi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1050 <err@plt>
mov    %rbx,%rdi
call   1030 <unlink@plt>
mov    %r12d,(%r15)
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [33 x i8] c"/tmp/unix_passfd.XXXXXXXXXXXXXXX\00"
@.str.1 = [16 x i8] c"%s: mkstemp(%s)\00"
define void @tempfile(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
store i8* %0, i8** %3
store i32* %1, i32** %4
%8 = load i32, i32* @PATH_MAX
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %5
%11 = alloca i8, i64 %9
store i64 %9, i64* %6
%12 = load i32, i32* @PATH_MAX
%13 = call i32 @snprintf(i8* %11, i32 %12, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @mkstemp(i8* %11)
store i32 %14, i32* %7
%15 = load i32, i32* %7
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = load i8*, i8** %3
%19 = call i32 @err(i32 -1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %18, i8* %11)
br label %20
20: ; preds = %17, %2
%21 = call i32 @unlink(i8* %11)
%22 = load i32, i32* %7
%23 = load i32*, i32** %4
store i32 %22, i32* %23
%24 = load i8*, i8** %5
ret void
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [33 x i8] c"/tmp/unix_passfd.XXXXXXXXXXXXXXX\00"
@.str.1 = [16 x i8] c"%s: mkstemp(%s)\00"
define void @tempfile(i8* %0, i32* nocapture writeonly %1) {
%3 = load i32, i32* @PATH_MAX
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = call i32 @snprintf(i8* %5, i32 %3, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @mkstemp(i8* %5)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 @err(i32 -1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %5)
br label %11
11: ; preds = %9, %2
%12 = call i32 @unlink(i8* %5)
store i32 %7, i32* %1
ret void
}