#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fdopen(int, char *);
int mkstemp(char *);
int /*<<< orphan*/ perror(char *);
scalar_t__ unlink(char *);
FILE *kdt_tmpfile(void) {
  char name[] = "kdtXXXXXX";
  int fd = mkstemp(name);
  if (fd == -1) {
    perror("kdt_tmpfile");
    exit(1);
  }
  FILE *fp = fdopen(fd, "r+w");
  assert(unlink(name) == 0);
  if (fp == NULL) {
    perror("kdt_tmpfile");
    exit(1);
  }
  return fp;
}


x86 assembly (clang, -O0):
<kdt_tmpfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0xe91(%rip),%rax
mov    %rax,-0xa(%rbp)
mov    0xe8e(%rip),%ax
mov    %ax,-0x2(%rbp)
lea    -0xa(%rbp),%rdi
call   1050 <mkstemp@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    11aa <kdt_tmpfile+0x4a>
lea    0xe6f(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%edi
lea    0xe62(%rip),%rsi
call   1060 <fdopen@plt>
mov    %rax,-0x18(%rbp)
lea    -0xa(%rbp),%rdi
call   1030 <unlink@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpq   $0x0,-0x18(%rbp)
jne    11f8 <kdt_tmpfile+0x98>
lea    0xe21(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kdt_tmpfile>:
push   %rbx
sub    $0x10,%rsp
movabs $0x585858585874646b,%rax
58 58 58
mov    %rax,(%rsp)
movw   $0x58,0x8(%rsp)
mov    %rsp,%rdi
call   1050 <mkstemp@plt>
cmp    $0xffffffff,%eax
je     11bc <kdt_tmpfile+0x5c>
lea    0xe88(%rip),%rsi
mov    %eax,%edi
call   1060 <fdopen@plt>
mov    %rax,%rbx
mov    %rsp,%rdi
call   1030 <unlink@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1040 <assert@plt>
test   %rbx,%rbx
je     11bc <kdt_tmpfile+0x5c>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe47(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@__const.kdt_tmpfile.name = [10 x i8] c"kdtXXXXXX\00"
@.str = [12 x i8] c"kdt_tmpfile\00"
@.str.1 = [4 x i8] c"r+w\00"
define i32* @kdt_tmpfile() {
%1 = alloca [10 x i8]
%2 = alloca i32
%3 = alloca i32*
%4 = bitcast [10 x i8]* %1 to i8*
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%6 = call i32 @mkstemp(i8* %5)
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %0
%13 = load i32, i32* %2
%14 = call i32* @fdopen(i32 %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %3
%15 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%16 = call i64 @unlink(i8* %15)
%17 = icmp eq i64 %16, 0
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = load i32*, i32** %3
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %25
22: ; preds = %12
%23 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %12
%26 = load i32*, i32** %3
ret i32* %26
}

LLVM IR (-O2):
@__const.kdt_tmpfile.name = [10 x i8] c"kdtXXXXXX\00"
@.str = [12 x i8] c"kdt_tmpfile\00"
@.str.1 = [4 x i8] c"r+w\00"
define noalias i32* @kdt_tmpfile() {
%1 = alloca [10 x i8]
%2 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%3 = call i32 @mkstemp(i8* %2)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @exit(i32 1)
unreachable
8: ; preds = %0
%9 = call i32* @fdopen(i32 %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%10 = call i64 @unlink(i8* %2)
%11 = icmp eq i64 %10, 0
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = icmp eq i32* %9, null
br i1 %14, label %15, label %18
15: ; preds = %8
%16 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %8
ret i32* %9
}