#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 O_CREAT;
int O_RDWR;
int O_TRUNC;
int PATH_MAX;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ mktemp(char *);
int open(char *, int, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int main(void) {
  static char template[] = "/tmp/myfileXXXXXX";
  char fname[PATH_MAX];
  static char mesg[] = "Here's lookin' at you, kid!\n";
  int fd;
  strcpy(fname, template);
  mktemp(fname);
  printf("Filename is %s\n", fname);
  fd = open(fname, O_CREAT | O_RDWR | O_TRUNC, 0600);
  write(fd, mesg, strlen(mesg));
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e5a(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x28(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x18(%rbp)
lea    0x2eae(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%rdi
call   1090 <mktemp@plt>
mov    -0x28(%rbp),%rsi
lea    0xe35(%rip),%rdi
call   1060 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    0x2e1d(%rip),%rax
mov    (%rax),%esi
mov    0x2dec(%rip),%rax
or     (%rax),%esi
mov    0x2e03(%rip),%rax
or     (%rax),%esi
mov    $0x180,%edx
call   1080 <open@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
lea    0x2e77(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x20(%rbp),%edi
mov    %eax,%edx
lea    0x2e66(%rip),%rsi
call   1040 <write@plt>
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
mov    0x2e62(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0x2ec8(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1090 <mktemp@plt>
lea    0xe51(%rip),%rdi
mov    %rbx,%rsi
call   1060 <printf@plt>
mov    0x2e3a(%rip),%rax
mov    0x2e0b(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e20(%rip),%rax
or     (%rax),%esi
mov    %rbx,%rdi
mov    $0x180,%edx
call   1080 <open@plt>
mov    %eax,%ebx
lea    0x2e98(%rip),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %ebx,%edi
call   1070 <close@plt>
xor    %eax,%eax
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@main.template = internal global [18 x i8] c"/tmp/myfileXXXXXX\00"
@PATH_MAX = global i32 0
@main.mesg = internal global [29 x i8] c"Here's lookin' at you, kid!\0A\00"
@.str = [16 x i8] c"Filename is %s\0A\00"
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@O_TRUNC = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i32
store i32 0, i32* %1
%5 = load i32, i32* @PATH_MAX
%6 = zext i32 %5 to i64
%7 = call i8* @llvm.stacksave()
store i8* %7, i8** %2
%8 = alloca i8, i64 %6
store i64 %6, i64* %3
%9 = call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @main.template, i64 0, i64 0))
%10 = call i32 @mktemp(i8* %8)
%11 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %8)
%12 = load i32, i32* @O_CREAT
%13 = load i32, i32* @O_RDWR
%14 = or i32 %12, %13
%15 = load i32, i32* @O_TRUNC
%16 = or i32 %14, %15
%17 = call i32 @open(i8* %8, i32 %16, i32 384)
store i32 %17, i32* %4
%18 = load i32, i32* %4
%19 = call i32 @strlen(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @main.mesg, i64 0, i64 0))
%20 = call i32 @write(i32 %18, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @main.mesg, i64 0, i64 0), i32 %19)
%21 = load i32, i32* %4
%22 = call i32 @close(i32 %21)
store i32 0, i32* %1
%23 = load i8*, i8** %2
%24 = load i32, i32* %1
ret i32 %24
}

LLVM IR (-O2):
@main.template = internal global [18 x i8] c"/tmp/myfileXXXXXX\00"
@PATH_MAX = global i32 0
@main.mesg = internal global [29 x i8] c"Here's lookin' at you, kid!\0A\00"
@.str = [16 x i8] c"Filename is %s\0A\00"
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@O_TRUNC = global i32 0
define i32 @main() {
%1 = load i32, i32* @PATH_MAX
%2 = zext i32 %1 to i64
%3 = alloca i8, i64 %2
%4 = call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @main.template, i64 0, i64 0))
%5 = call i32 @mktemp(i8* %3)
%6 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %3)
%7 = load i32, i32* @O_CREAT
%8 = load i32, i32* @O_RDWR
%9 = or i32 %8, %7
%10 = load i32, i32* @O_TRUNC
%11 = or i32 %9, %10
%12 = call i32 @open(i8* %3, i32 %11, i32 384)
%13 = call i32 @strlen(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @main.mesg, i64 0, i64 0))
%14 = call i32 @write(i32 %12, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @main.mesg, i64 0, i64 0), i32 %13)
%15 = call i32 @close(i32 %12)
ret i32 0
}