#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 */
char *build_template(char const *, char const *, char const *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ free(char *);
int mkstemp(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ process_args(int, char **, char const **, char const **,
                                char const **);
int /*<<< orphan*/ puts(char *);
size_t strlen(char const *);
int main(int argc, char *argv[]) {
  const char *directory = "", *prefix = "", *suffix = "";
  size_t suffix_len;
  int fd;
  char *template;
  process_args(argc, argv, &directory, &prefix, &suffix);
  if ((template = build_template(directory, prefix, suffix)) == NULL) {
    return 1;
  }
  if ((suffix_len = strlen(suffix)) > 0) {
    fd = 0;
  } else {
    if ((fd = mkstemp(template)) < 0) {
      perror("mkstemp");
    }
  }
  if (fd >= 0) {
    (void)puts(template);
    (void)close(fd);
  }
  free(template);
  return fd >= 0 ? 0 : 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe6a(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xe5f(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xe54(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x20(%rbp),%rcx
lea    -0x28(%rbp),%r8
call   10a0 <process_args@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1080 <build_template@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    11fa <main+0x7a>
movl   $0x1,-0x4(%rbp)
jmp    127a <main+0xfa>
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jbe    121d <main+0x9d>
movl   $0x0,-0x34(%rbp)
jmp    1243 <main+0xc3>
mov    -0x40(%rbp),%rdi
call   1070 <mkstemp@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jge    123e <main+0xbe>
lea    0xdc7(%rip),%rdi
call   1090 <perror@plt>
jmp    1243 <main+0xc3>
cmpl   $0x0,-0x34(%rbp)
jl     125e <main+0xde>
mov    -0x40(%rbp),%rdi
call   1040 <puts@plt>
mov    -0x34(%rbp),%edi
call   1060 <close@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x34(%rbp),%edx
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    $0x0,%edx
cmovge %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
lea    0xe88(%rip),%rax
mov    %rax,0x18(%rsp)
mov    %rax,0x10(%rsp)
mov    %rax,0x8(%rsp)
lea    0x18(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0x8(%rsp),%r8
call   1090 <process_args@plt>
mov    0x18(%rsp),%rdi
mov    0x10(%rsp),%rsi
mov    0x8(%rsp),%rdx
call   1070 <build_template@plt>
test   %rax,%rax
je     11f7 <main+0x87>
mov    %rax,%rbx
mov    0x8(%rsp),%rax
xor    %r14d,%r14d
cmpb   $0x0,(%rax)
mov    $0x0,%ebp
jne    11de <main+0x6e>
mov    %rbx,%rdi
call   1060 <mkstemp@plt>
mov    %eax,%ebp
test   %eax,%eax
js     1209 <main+0x99>
mov    %rbx,%rdi
call   1040 <puts@plt>
mov    %ebp,%edi
call   1050 <close@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    11fd <main+0x8d>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xdf0(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%r14d
jmp    11ed <main+0x7d>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [8 x i8] c"mkstemp\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %6
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %7
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %8
%12 = load i32, i32* %4
%13 = load i8**, i8*** %5
%14 = call i32 @process_args(i32 %12, i8** %13, i8** %6, i8** %7, i8** %8)
%15 = load i8*, i8** %6
%16 = load i8*, i8** %7
%17 = load i8*, i8** %8
%18 = call i8* @build_template(i8* %15, i8* %16, i8* %17)
store i8* %18, i8** %11
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %21
20: ; preds = %2
store i32 1, i32* %3
br label %48
21: ; preds = %2
%22 = load i8*, i8** %8
%23 = call i64 @strlen(i8* %22)
store i64 %23, i64* %9
%24 = icmp ugt i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %21
store i32 0, i32* %10
br label %33
26: ; preds = %21
%27 = load i8*, i8** %11
%28 = call i32 @mkstemp(i8* %27)
store i32 %28, i32* %10
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %32
32: ; preds = %30, %26
br label %33
33: ; preds = %32, %25
%34 = load i32, i32* %10
%35 = icmp sge i32 %34, 0
br i1 %35, label %36, label %41
36: ; preds = %33
%37 = load i8*, i8** %11
%38 = call i32 @puts(i8* %37)
%39 = load i32, i32* %10
%40 = call i32 @close(i32 %39)
br label %41
41: ; preds = %36, %33
%42 = load i8*, i8** %11
%43 = call i32 @free(i8* %42)
%44 = load i32, i32* %10
%45 = icmp sge i32 %44, 0
%46 = zext i1 %45 to i64
%47 = select i1 %45, i32 0, i32 1
store i32 %47, i32* %3
br label %48
48: ; preds = %41, %20
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [8 x i8] c"mkstemp\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = bitcast i8** %3 to i8*
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %3
%7 = bitcast i8** %4 to i8*
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %4
%8 = bitcast i8** %5 to i8*
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %5
%9 = call i32 @process_args(i32 %0, i8** %1, i8** %3, i8** %4, i8** %5)
%10 = load i8*, i8** %3
%11 = load i8*, i8** %4
%12 = load i8*, i8** %5
%13 = call i8* @build_template(i8* %10, i8* %11, i8* %12)
%14 = icmp eq i8* %13, null
br i1 %14, label %31, label %15
15: ; preds = %2
%16 = load i8*, i8** %5
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %15
%20 = call i32 @mkstemp(i8* %13)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %28
24: ; preds = %19, %15
%25 = phi i32 [ 0, %15 ], [ %20, %19 ]
%26 = call i32 @puts(i8* %13)
%27 = call i32 @close(i32 %25)
br label %28
28: ; preds = %22, %24
%29 = phi i32 [ 0, %24 ], [ 1, %22 ]
%30 = call i32 @free(i8* %13)
br label %31
31: ; preds = %2, %28
%32 = phi i32 [ %29, %28 ], [ 1, %2 ]
ret i32 %32
}