#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*/ PATH_MAX;
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fdopen(int, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int mkstemp(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strerror(scalar_t__);
int /*<<< orphan*/ unlink(char *);
FILE *makeTempFile(char *path) {
  char template[PATH_MAX + 1];
  int fildes;
  FILE *F;
  if (path) {
    strcpy(template, path);
    strcat(template, "/XXXXXX");
  } else {
    strcpy(template, "XXXXXX");
  }
  errno = 0;
  fildes = mkstemp(template);
  if (errno) {
    fprintf(stderr, "Failed to create temporary file '%s': %s\n", template,
            strerror(errno));
    exit(1);
  }
  errno = 0;
  F = fdopen(fildes, "w+");
  if (errno) {
    fprintf(stderr, "Failed to open temporary file '%s': %s\n", template,
            strerror(errno));
    exit(1);
  }
  errno = 0;
  unlink(template);
  if (errno) {
    fprintf(stderr, "Failed to hide temporary file '%s': %s\n", template,
            strerror(errno));
    exit(1);
  }
  return (F);
}


x86 assembly (clang, -O0):
<makeTempFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e5d(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11e8 <makeTempFile+0x68>
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x30(%rbp),%rdi
lea    0xe22(%rip),%rsi
call   1080 <strcat@plt>
jmp    11f8 <makeTempFile+0x78>
mov    -0x30(%rbp),%rdi
lea    0xe0e(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x30(%rbp),%rdi
mov    0x2dcd(%rip),%rax
movq   $0x0,(%rax)
call   1060 <mkstemp@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2db7(%rip),%rax
cmpq   $0x0,(%rax)
je     125e <makeTempFile+0xde>
mov    0x2dae(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2d9a(%rip),%rax
mov    (%rax),%rdi
call   10a0 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    %rax,%rcx
lea    0xdb9(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2d6b(%rip),%rax
movq   $0x0,(%rax)
mov    -0x1c(%rbp),%edi
lea    0xdbc(%rip),%rsi
call   1070 <fdopen@plt>
mov    %rax,-0x28(%rbp)
mov    0x2d4a(%rip),%rax
cmpq   $0x0,(%rax)
je     12cb <makeTempFile+0x14b>
mov    0x2d41(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2d2d(%rip),%rax
mov    (%rax),%rdi
call   10a0 <strerror@plt>
mov    -0x38(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    %rax,%rcx
lea    0xd79(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x30(%rbp),%rdi
mov    0x2cfa(%rip),%rax
movq   $0x0,(%rax)
call   1030 <unlink@plt>
mov    0x2ce7(%rip),%rax
cmpq   $0x0,(%rax)
je     132e <makeTempFile+0x1ae>
mov    0x2cde(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2cca(%rip),%rax
mov    (%rax),%rdi
call   10a0 <strerror@plt>
mov    -0x3c(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    %rax,%rcx
lea    0xd3e(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<makeTempFile>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2e5f(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%r15
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
test   %rdi,%rdi
je     11c8 <makeTempFile+0x48>
mov    %rdi,%rsi
mov    %r15,%rdi
call   1040 <strcpy@plt>
lea    0xe42(%rip),%rsi
mov    %r15,%rdi
call   1080 <strcat@plt>
jmp    11d7 <makeTempFile+0x57>
lea    0xe32(%rip),%rsi
mov    %r15,%rdi
call   1040 <strcpy@plt>
mov    0x2df2(%rip),%rbx
movq   $0x0,(%rbx)
mov    %r15,%rdi
call   1060 <mkstemp@plt>
mov    (%rbx),%rdi
test   %rdi,%rdi
jne    123a <makeTempFile+0xba>
movq   $0x0,(%rbx)
lea    0xe2f(%rip),%rsi
mov    %eax,%edi
call   1070 <fdopen@plt>
mov    (%rbx),%rdi
test   %rdi,%rdi
jne    1252 <makeTempFile+0xd2>
mov    %rax,%r14
movq   $0x0,(%rbx)
mov    %r15,%rdi
call   1030 <unlink@plt>
mov    (%rbx),%rdi
test   %rdi,%rdi
jne    126a <makeTempFile+0xea>
mov    %r14,%rax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d97(%rip),%rax
mov    (%rax),%r14d
call   10a0 <strerror@plt>
lea    0xdb8(%rip),%rsi
jmp    1280 <makeTempFile+0x100>
mov    0x2d7f(%rip),%rax
mov    (%rax),%r14d
call   10a0 <strerror@plt>
lea    0xdcd(%rip),%rsi
jmp    1280 <makeTempFile+0x100>
mov    0x2d67(%rip),%rax
mov    (%rax),%r14d
call   10a0 <strerror@plt>
lea    0xddd(%rip),%rsi
mov    %r14d,%edi
mov    %r15,%rdx
mov    %rax,%rcx
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [8 x i8] c"/XXXXXX\00"
@.str.1 = [7 x i8] c"XXXXXX\00"
@errno = global i64 0
@stderr = global i32 0
@.str.2 = [42 x i8] c"Failed to create temporary file '%s': %s\0A\00"
@.str.3 = [3 x i8] c"w+\00"
@.str.4 = [40 x i8] c"Failed to open temporary file '%s': %s\0A\00"
@.str.5 = [40 x i8] c"Failed to hide temporary file '%s': %s\0A\00"
define i32* @makeTempFile(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32*
store i8* %0, i8** %2
%7 = load i32, i32* @PATH_MAX
%8 = add nsw i32 %7, 1
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %3
%11 = alloca i8, i64 %9
store i64 %9, i64* %4
%12 = load i8*, i8** %2
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %18
14: ; preds = %1
%15 = load i8*, i8** %2
%16 = call i32 @strcpy(i8* %11, i8* %15)
%17 = call i32 @strcat(i8* %11, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %20
18: ; preds = %1
%19 = call i32 @strcpy(i8* %11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %18, %14
store i64 0, i64* @errno
%21 = call i32 @mkstemp(i8* %11)
store i32 %21, i32* %5
%22 = load i64, i64* @errno
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %30
24: ; preds = %20
%25 = load i32, i32* @stderr
%26 = load i64, i64* @errno
%27 = call i8* @strerror(i64 %26)
%28 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i8* %11, i8* %27)
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %20
store i64 0, i64* @errno
%31 = load i32, i32* %5
%32 = call i32* @fdopen(i32 %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %32, i32** %6
%33 = load i64, i64* @errno
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %41
35: ; preds = %30
%36 = load i32, i32* @stderr
%37 = load i64, i64* @errno
%38 = call i8* @strerror(i64 %37)
%39 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i8* %11, i8* %38)
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %30
store i64 0, i64* @errno
%42 = call i32 @unlink(i8* %11)
%43 = load i64, i64* @errno
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %51
45: ; preds = %41
%46 = load i32, i32* @stderr
%47 = load i64, i64* @errno
%48 = call i8* @strerror(i64 %47)
%49 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i8* %11, i8* %48)
%50 = call i32 @exit(i32 1)
unreachable
51: ; preds = %41
%52 = load i32*, i32** %6
%53 = load i8*, i8** %3
ret i32* %52
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [8 x i8] c"/XXXXXX\00"
@.str.1 = [7 x i8] c"XXXXXX\00"
@errno = global i64 0
@stderr = global i32 0
@.str.2 = [42 x i8] c"Failed to create temporary file '%s': %s\0A\00"
@.str.3 = [3 x i8] c"w+\00"
@.str.4 = [40 x i8] c"Failed to open temporary file '%s': %s\0A\00"
@.str.5 = [40 x i8] c"Failed to hide temporary file '%s': %s\0A\00"
define noalias i32* @makeTempFile(i8* %0) {
%2 = load i32, i32* @PATH_MAX
%3 = add nsw i32 %2, 1
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = icmp eq i8* %0, null
br i1 %6, label %10, label %7
7: ; preds = %1
%8 = call i32 @strcpy(i8* %5, i8* %0)
%9 = call i32 @strcat(i8* %5, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %12
10: ; preds = %1
%11 = call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %7
store i64 0, i64* @errno
%13 = call i32 @mkstemp(i8* %5)
%14 = load i64, i64* @errno
%15 = icmp eq i64 %14, 0
br i1 %15, label %21, label %16
16: ; preds = %12
%17 = load i32, i32* @stderr
%18 = call i8* @strerror(i64 %14)
%19 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i8* %5, i8* %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %12
store i64 0, i64* @errno
%22 = call i32* @fdopen(i32 %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%23 = load i64, i64* @errno
%24 = icmp eq i64 %23, 0
br i1 %24, label %30, label %25
25: ; preds = %21
%26 = load i32, i32* @stderr
%27 = call i8* @strerror(i64 %23)
%28 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i8* %5, i8* %27)
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %21
store i64 0, i64* @errno
%31 = call i32 @unlink(i8* %5)
%32 = load i64, i64* @errno
%33 = icmp eq i64 %32, 0
br i1 %33, label %39, label %34
34: ; preds = %30
%35 = load i32, i32* @stderr
%36 = call i8* @strerror(i64 %32)
%37 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i8* %5, i8* %36)
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %30
ret i32* %22
}