#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
char *mkdtemp(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int main(int argc, char **argv) {
  char template[256];
  char *dir;
  if (argc == 1) {
    strcpy(template, "/tmp/tempdirXXXXXX");
  } else {
    if (strlen(argv[1]) > 256 - 6 - 1) {
      fprintf(stderr, "Template cannot be larger than %d characters.\n",
              256 - 6 - 1);
      return EXIT_FAILURE;
    }
    strcpy(template, argv[1]);
    strcpy(template + strlen(argv[1]), "XXXXXX");
  }
  dir = mkdtemp(template);
  if (!dir) {
    perror("tempdir: could not create temporary directory");
    exit(1);
  }
  printf("Directory created : %s\n", dir);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11ab <main+0x3b>
lea    -0x110(%rbp),%rdi
lea    0xe5f(%rip),%rsi
call   1030 <strcpy@plt>
jmp    1235 <main+0xc5>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <strlen@plt>
cmp    $0xf9,%eax
jle    11ee <main+0x7e>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
lea    0xe40(%rip),%rsi
mov    $0xf9,%edx
call   1060 <fprintf@plt>
mov    0x2df4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    128b <main+0x11b>
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <strcpy@plt>
lea    -0x110(%rbp),%rax
mov    %rax,-0x120(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <strlen@plt>
mov    -0x120(%rbp),%rdi
cltq
add    %rax,%rdi
lea    0xddc(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x110(%rbp),%rdi
call   1070 <mkdtemp@plt>
mov    %rax,-0x118(%rbp)
cmpq   $0x0,-0x118(%rbp)
jne    126c <main+0xfc>
lea    0xde5(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x118(%rbp),%rsi
lea    0xdf6(%rip),%rdi
call   1050 <printf@plt>
mov    0x2d4a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x100,%rsp
cmp    $0x1,%edi
jne    1189 <main+0x19>
lea    0xe7c(%rip),%rsi
mov    %rsp,%rdi
jmp    11e1 <main+0x71>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1040 <strlen@plt>
cmp    $0xfa,%eax
jl     11bf <main+0x4f>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
lea    0xe67(%rip),%rsi
mov    $0xf9,%edx
call   1060 <fprintf@plt>
mov    0x2e1b(%rip),%rax
jmp    1209 <main+0x99>
mov    0x8(%rbx),%rsi
mov    %rsp,%rdi
call   1030 <strcpy@plt>
mov    0x8(%rbx),%rdi
call   1040 <strlen@plt>
cltq
lea    (%rsp,%rax,1),%rdi
lea    0xe2b(%rip),%rsi
call   1030 <strcpy@plt>
mov    %rsp,%rdi
call   1070 <mkdtemp@plt>
test   %rax,%rax
je     1214 <main+0xa4>
lea    0xe76(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
mov    0x2dc7(%rip),%rax
mov    (%rax),%eax
add    $0x100,%rsp
pop    %rbx
ret
lea    0xe27(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"/tmp/tempdirXXXXXX\00"
@stderr = global i32 0
@.str.1 = [47 x i8] c"Template cannot be larger than %d characters.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [7 x i8] c"XXXXXX\00"
@.str.3 = [46 x i8] c"tempdir: could not create temporary directory\00"
@.str.4 = [24 x i8] c"Directory created : %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [256 x i8]
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%12 = call i32 @strcpy(i8* %11, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %37
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @strlen(i8* %16)
%18 = icmp sgt i32 %17, 249
br i1 %18, label %19, label %23
19: ; preds = %13
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i32 249)
%22 = load i32, i32* @EXIT_FAILURE
store i32 %22, i32* %3
br label %49
23: ; preds = %13
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 @strcpy(i8* %24, i8* %27)
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i32 @strlen(i8* %32)
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %29, i64 %34
%36 = call i32 @strcpy(i8* %35, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %37
37: ; preds = %23, %10
%38 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%39 = call i8* @mkdtemp(i8* %38)
store i8* %39, i8** %7
%40 = load i8*, i8** %7
%41 = icmp ne i8* %40, null
br i1 %41, label %45, label %42
42: ; preds = %37
%43 = call i32 @perror(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0))
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %37
%46 = load i8*, i8** %7
%47 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %46)
%48 = load i32, i32* @EXIT_SUCCESS
store i32 %48, i32* %3
br label %49
49: ; preds = %45, %19
%50 = load i32, i32* %3
ret i32 %50
}

LLVM IR (-O2):
@.str = [19 x i8] c"/tmp/tempdirXXXXXX\00"
@stderr = global i32 0
@.str.1 = [47 x i8] c"Template cannot be larger than %d characters.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [7 x i8] c"XXXXXX\00"
@.str.3 = [46 x i8] c"tempdir: could not create temporary directory\00"
@.str.4 = [24 x i8] c"Directory created : %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 1
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %24
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @strlen(i8* %10)
%12 = icmp sgt i32 %11, 249
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i32 249)
br label %32
16: ; preds = %8
%17 = load i8*, i8** %9
%18 = call i32 @strcpy(i8* %4, i8* %17)
%19 = load i8*, i8** %9
%20 = call i32 @strlen(i8* %19)
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %21
%23 = call i32 @strcpy(i8* %22, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %24
24: ; preds = %16, %6
%25 = call i8* @mkdtemp(i8* %4)
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = call i32 @perror(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %24
%31 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %25)
br label %32
32: ; preds = %30, %13
%33 = phi i32* [ @EXIT_SUCCESS, %30 ], [ @EXIT_FAILURE, %13 ]
%34 = load i32, i32* %33
ret i32 %34
}