#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 _error(char const *, char *, int);
scalar_t__ close(int);
int mkstemp(char *);
int /*<<< orphan*/ printf(char *, char const *);
scalar_t__ unlink(char *);
int _mkstemp(char const *progname) {
  int ret = 0;
  char buf[] = "/tmp/stdlib.XXXXXX";
  int fd;
  printf("%s: Testing mkstemp()\n", progname);
  if ((fd = mkstemp(buf)) < 0)
    return _error(progname, "mkstemp", 1);
  if (unlink(buf) != 0)
    ret = _error(progname, "unlink", 1);
  if (close(fd) != 0)
    ret = _error(progname, "close", 1);
  return ret;
}


x86 assembly (clang, -O0):
<_mkstemp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    0xe96(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe93(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xe90(%rip),%ax
mov    %ax,-0x20(%rbp)
mov    0xe88(%rip),%al
mov    %al,-0x1e(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe7b(%rip),%rdi
call   1040 <printf@plt>
lea    -0x30(%rbp),%rdi
call   1070 <mkstemp@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jge    11cf <_mkstemp+0x7f>
mov    -0x10(%rbp),%rdi
lea    0xe6d(%rip),%rsi
mov    $0x1,%edx
call   1060 <_error@plt>
mov    %eax,-0x4(%rbp)
jmp    122a <_mkstemp+0xda>
lea    -0x30(%rbp),%rdi
call   1030 <unlink@plt>
cmp    $0x0,%rax
je     11fa <_mkstemp+0xaa>
mov    -0x10(%rbp),%rdi
lea    0xe45(%rip),%rsi
mov    $0x1,%edx
call   1060 <_error@plt>
mov    %eax,-0x14(%rbp)
mov    -0x34(%rbp),%edi
call   1050 <close@plt>
cmp    $0x0,%rax
je     1224 <_mkstemp+0xd4>
mov    -0x10(%rbp),%rdi
lea    0xe22(%rip),%rsi
mov    $0x1,%edx
call   1060 <_error@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_mkstemp>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%r14
movaps 0xe9e(%rip),%xmm0
movaps %xmm0,(%rsp)
movl   $0x585858,0xf(%rsp)
lea    0xe9e(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
mov    %rsp,%rdi
call   1070 <mkstemp@plt>
test   %eax,%eax
js     11b0 <_mkstemp+0x60>
mov    %eax,%ebp
mov    %rsp,%rdi
call   1030 <unlink@plt>
test   %rax,%rax
je     11b9 <_mkstemp+0x69>
lea    0xe93(%rip),%rsi
mov    %r14,%rdi
mov    $0x1,%edx
call   1060 <_error@plt>
mov    %eax,%ebx
jmp    11bb <_mkstemp+0x6b>
lea    0xe73(%rip),%rsi
jmp    11ce <_mkstemp+0x7e>
xor    %ebx,%ebx
mov    %ebp,%edi
call   1050 <close@plt>
test   %rax,%rax
je     11dd <_mkstemp+0x8d>
lea    0xe6b(%rip),%rsi
mov    %r14,%rdi
mov    $0x1,%edx
call   1060 <_error@plt>
mov    %eax,%ebx
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@__const._mkstemp.buf = [19 x i8] c"/tmp/stdlib.XXXXXX\00"
@.str = [23 x i8] c"%s: Testing mkstemp()\0A\00"
@.str.1 = [8 x i8] c"mkstemp\00"
@.str.2 = [7 x i8] c"unlink\00"
@.str.3 = [6 x i8] c"close\00"
define i32 @_mkstemp(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [19 x i8]
%6 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %4
%7 = bitcast [19 x i8]* %5 to i8*
%8 = load i8*, i8** %3
%9 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = getelementptr inbounds [19 x i8], [19 x i8]* %5, i64 0, i64 0
%11 = call i32 @mkstemp(i8* %10)
store i32 %11, i32* %6
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %1
%14 = load i8*, i8** %3
%15 = call i32 @_error(i8* %14, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 1)
store i32 %15, i32* %2
br label %32
16: ; preds = %1
%17 = getelementptr inbounds [19 x i8], [19 x i8]* %5, i64 0, i64 0
%18 = call i64 @unlink(i8* %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = load i8*, i8** %3
%22 = call i32 @_error(i8* %21, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 1)
store i32 %22, i32* %4
br label %23
23: ; preds = %20, %16
%24 = load i32, i32* %6
%25 = call i64 @close(i32 %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %23
%28 = load i8*, i8** %3
%29 = call i32 @_error(i8* %28, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 1)
store i32 %29, i32* %4
br label %30
30: ; preds = %27, %23
%31 = load i32, i32* %4
store i32 %31, i32* %2
br label %32
32: ; preds = %30, %13
%33 = load i32, i32* %2
ret i32 %33
}

LLVM IR (-O2):
@__const._mkstemp.buf = [19 x i8] c"/tmp/stdlib.XXXXXX\00"
@.str = [23 x i8] c"%s: Testing mkstemp()\0A\00"
@.str.1 = [8 x i8] c"mkstemp\00"
@.str.2 = [7 x i8] c"unlink\00"
@.str.3 = [6 x i8] c"close\00"
define i32 @_mkstemp(i8* %0) {
%2 = alloca [19 x i8]
%3 = getelementptr inbounds [19 x i8], [19 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %0)
%5 = call i32 @mkstemp(i8* %3)
%6 = icmp slt i32 %5, 0
br i1 %6, label %16, label %7
7: ; preds = %1
%8 = call i64 @unlink(i8* %3)
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = call i32 @_error(i8* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 1)
br label %12
12: ; preds = %10, %7
%13 = phi i32 [ %11, %10 ], [ 0, %7 ]
%14 = call i64 @close(i32 %5)
%15 = icmp eq i64 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %12, %1
%17 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), %1 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), %12 ]
%18 = call i32 @_error(i8* %0, i8* %17, i32 1)
br label %19
19: ; preds = %16, %12
%20 = phi i32 [ %13, %12 ], [ %18, %16 ]
ret i32 %20
}