#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*/ errno;
int /*<<< orphan*/ getpid();
int mkstemp(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ set_sting_pid(int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char *);
char *strerror(int /*<<< orphan*/);
int main(int argc, char **argv) {
  int fd, i;
  char template[64];
  set_sting_pid(getpid());
  for (i = 0; i < 2; i++) {
    sprintf(template, "%sXXXXXX", "/tmp/my_file");
    fd = mkstemp(template);
    printf("Attempting to create file: %s\n", template);
    if (fd < 0)
      printf("mkstemp failed: %s\n", strerror(errno));
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%edi
call   1050 <set_sting_pid@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x2,-0x18(%rbp)
jge    1202 <main+0xa2>
lea    -0x60(%rbp),%rdi
lea    0xe60(%rip),%rsi
lea    0xe62(%rip),%rdx
call   1070 <sprintf@plt>
lea    -0x60(%rbp),%rdi
call   1060 <mkstemp@plt>
mov    %eax,-0x14(%rbp)
lea    -0x60(%rbp),%rsi
lea    0xe53(%rip),%rdi
call   1040 <printf@plt>
cmpl   $0x0,-0x14(%rbp)
jge    11ef <main+0x8f>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    %rax,%rsi
lea    0xe4b(%rip),%rdi
call   1040 <printf@plt>
jmp    11f4 <main+0x94>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    118b <main+0x2b>
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x48,%rsp
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%edi
call   1050 <set_sting_pid@plt>
lea    0xe85(%rip),%rsi
lea    0xe87(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1070 <sprintf@plt>
mov    %rbx,%rdi
call   1060 <mkstemp@plt>
mov    %eax,%ebp
lea    0xe78(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
test   %ebp,%ebp
jns    11c7 <main+0x67>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe76(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
lea    0xe32(%rip),%rsi
lea    0xe34(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1070 <sprintf@plt>
mov    %rbx,%rdi
call   1060 <mkstemp@plt>
mov    %eax,%ebp
lea    0xe25(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
test   %ebp,%ebp
jns    121a <main+0xba>
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe23(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"%sXXXXXX\00"
@.str.1 = [13 x i8] c"/tmp/my_file\00"
@.str.2 = [31 x i8] c"Attempting to create file: %s\0A\00"
@.str.3 = [20 x i8] c"mkstemp failed: %s\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [64 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 (...) @getpid()
%10 = call i32 @set_sting_pid(i32 %9)
store i32 0, i32* %7
br label %11
11: ; preds = %28, %2
%12 = load i32, i32* %7
%13 = icmp slt i32 %12, 2
br i1 %13, label %14, label %31
14: ; preds = %11
%15 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%16 = call i32 @sprintf(i8* %15, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%17 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%18 = call i32 @mkstemp(i8* %17)
store i32 %18, i32* %6
%19 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%20 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %19)
%21 = load i32, i32* %6
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %14
%24 = load i32, i32* @errno
%25 = call i8* @strerror(i32 %24)
%26 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %25)
br label %27
27: ; preds = %23, %14
br label %28
28: ; preds = %27
%29 = load i32, i32* %7
%30 = add nsw i32 %29, 1
store i32 %30, i32* %7
br label %11
31: ; preds = %11
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
@.str = [9 x i8] c"%sXXXXXX\00"
@.str.1 = [13 x i8] c"/tmp/my_file\00"
@.str.2 = [31 x i8] c"Attempting to create file: %s\0A\00"
@.str.3 = [20 x i8] c"mkstemp failed: %s\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [64 x i8]
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%5 = tail call i32 (...) @getpid()
%6 = tail call i32 @set_sting_pid(i32 %5)
%7 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @mkstemp(i8* %4)
%9 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%10 = icmp slt i32 %8, 0
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i32, i32* @errno
%13 = call i8* @strerror(i32 %12)
%14 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %13)
br label %15
15: ; preds = %2, %11
%16 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @mkstemp(i8* %4)
%18 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%19 = icmp slt i32 %17, 0
br i1 %19, label %20, label %24
20: ; preds = %15
%21 = load i32, i32* @errno
%22 = call i8* @strerror(i32 %21)
%23 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %22)
br label %24
24: ; preds = %20, %15
ret i32 0
}