#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*/ err_sys(char *);
int errno;
int mkstemp(char *);
char *mktemp(char *);
int /*<<< orphan*/ printf(char *, char *, ...);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ unlink(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  char line[4096];
  strcpy(line, "/tmp/this_is_a_temp_file_XXXXXX");
  int fd = mkstemp(line);
  if (fd == 0)
    err_sys("mkstemp error");
  printf("%s\n", line);
  write(fd, line, strlen(line));
  unlink(line);
  strcpy(line, "/tmp/that_is_a_temp_file_XXXXXX");
  char *ptr = mktemp(line);
  printf("%s, errno = %d\n", ptr, errno);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x1010(%rbp),%rdi
lea    0xe59(%rip),%rsi
call   1040 <strcpy@plt>
lea    -0x1010(%rbp),%rdi
call   1090 <mkstemp@plt>
mov    %eax,-0x1014(%rbp)
cmpl   $0x0,-0x1014(%rbp)
jne    11d7 <main+0x57>
lea    0xe4e(%rip),%rdi
call   1050 <err_sys@plt>
lea    -0x1010(%rbp),%rsi
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x1014(%rbp),%eax
mov    %eax,-0x102c(%rbp)
lea    -0x1010(%rbp),%rax
mov    %rax,-0x1028(%rbp)
lea    -0x1010(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x102c(%rbp),%edi
mov    -0x1028(%rbp),%rsi
mov    %eax,%edx
call   1060 <write@plt>
lea    -0x1010(%rbp),%rdi
call   1030 <unlink@plt>
lea    -0x1010(%rbp),%rdi
lea    0xdf2(%rip),%rsi
call   1040 <strcpy@plt>
lea    -0x1010(%rbp),%rdi
call   10a0 <mktemp@plt>
mov    %rax,-0x1020(%rbp)
mov    -0x1020(%rbp),%rsi
mov    0x2d7a(%rip),%rax
mov    (%rax),%edx
lea    0xde3(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
xor    %eax,%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x1008,%rsp
lea    0xe70(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
call   1090 <mkstemp@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    11b5 <main+0x35>
lea    0xe70(%rip),%rdi
call   1050 <err_sys@plt>
lea    0xe72(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %rbx,%rdi
call   1070 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1060 <write@plt>
mov    %rbx,%rdi
call   1030 <unlink@plt>
lea    0xe46(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
call   10a0 <mktemp@plt>
mov    0x2ddd(%rip),%rcx
mov    (%rcx),%edx
lea    0xe46(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
xor    %eax,%eax
add    $0x1008,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"/tmp/this_is_a_temp_file_XXXXXX\00"
@.str.1 = [14 x i8] c"mkstemp error\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [32 x i8] c"/tmp/that_is_a_temp_file_XXXXXX\00"
@.str.4 = [16 x i8] c"%s, errno = %d\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [4096 x i8]
%7 = alloca i32
%8 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%10 = call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%11 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%12 = call i32 @mkstemp(i8* %11)
store i32 %12, i32* %7
%13 = load i32, i32* %7
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 @err_sys(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %15, %2
%18 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%19 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %18)
%20 = load i32, i32* %7
%21 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%22 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%23 = call i32 @strlen(i8* %22)
%24 = call i32 @write(i32 %20, i8* %21, i32 %23)
%25 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%26 = call i32 @unlink(i8* %25)
%27 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%28 = call i32 @strcpy(i8* %27, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
%29 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%30 = call i8* @mktemp(i8* %29)
store i8* %30, i8** %8
%31 = load i8*, i8** %8
%32 = load i32, i32* @errno
%33 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* %31, i32 %32)
ret i32 0
}

LLVM IR (-O2):
@.str = [32 x i8] c"/tmp/this_is_a_temp_file_XXXXXX\00"
@.str.1 = [14 x i8] c"mkstemp error\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [32 x i8] c"/tmp/that_is_a_temp_file_XXXXXX\00"
@.str.4 = [16 x i8] c"%s, errno = %d\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @mkstemp(i8* %4)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = call i32 @err_sys(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %10
10: ; preds = %8, %2
%11 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%12 = call i32 @strlen(i8* %4)
%13 = call i32 @write(i32 %6, i8* %4, i32 %12)
%14 = call i32 @unlink(i8* %4)
%15 = call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
%16 = call i8* @mktemp(i8* %4)
%17 = load i32, i32* @errno
%18 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* %16, i32 %17)
ret i32 0
}