#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int mkstemp(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ *tmpfile();
int /*<<< orphan*/ unlink(char *);
int main(int argc, char *argv[]) {
  int fd;
  char fileName[] = "/tmp/foobarXXXXXX";
  FILE *file;
  fd = mkstemp(fileName);
  if (fd == -1) {
    fprintf(stderr, "error on mkstep\n");
    exit(EXIT_FAILURE);
  }
  fprintf(stdout, "%s is the generated filename\n", fileName);
  unlink(fileName);
  if (close(fd) == -1) {
    fprintf(stderr, "error on close\n");
    exit(EXIT_FAILURE);
  }
  file = tmpfile();
  fclose(file);
  exit(EXIT_SUCCESS);
}


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)
mov    0xe73(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe70(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xe6d(%rip),%ax
mov    %ax,-0x20(%rbp)
lea    -0x30(%rbp),%rdi
call   1080 <mkstemp@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11e2 <main+0x72>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
lea    0xe45(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rdx
lea    0xe2d(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
lea    -0x30(%rbp),%rdi
call   1030 <unlink@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
jne    123c <main+0xcc>
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
lea    0xe1a(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2da3(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    $0x0,%al
call   1060 <tmpfile@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2d71(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movaps 0xe82(%rip),%xmm0
movaps %xmm0,(%rsp)
movw   $0x58,0x10(%rsp)
mov    %rsp,%rdi
call   1080 <mkstemp@plt>
cmp    $0xffffffff,%eax
jne    11a8 <main+0x38>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
lea    0xe6c(%rip),%rsi
jmp    11eb <main+0x7b>
mov    %eax,%ebx
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
lea    0xe69(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %r14,%rdi
call   1030 <unlink@plt>
mov    %ebx,%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
jne    1200 <main+0x90>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
lea    0xe56(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
xor    %eax,%eax
call   1060 <tmpfile@plt>
mov    %rax,%rdi
call   1040 <fclose@plt>
mov    0x2db2(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@__const.main.fileName = [18 x i8] c"/tmp/foobarXXXXXX\00"
@stderr = global i32 0
@.str = [17 x i8] c"error on mkstep\0A\00"
@EXIT_FAILURE = global i32 0
@stdout = global i32 0
@.str.1 = [30 x i8] c"%s is the generated filename\0A\00"
@.str.2 = [16 x i8] c"error on close\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 i32
%7 = alloca [18 x i8]
%8 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = bitcast [18 x i8]* %7 to i8*
%10 = getelementptr inbounds [18 x i8], [18 x i8]* %7, i64 0, i64 0
%11 = call i32 @mkstemp(i8* %10)
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %2
%20 = load i32, i32* @stdout
%21 = getelementptr inbounds [18 x i8], [18 x i8]* %7, i64 0, i64 0
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %21)
%23 = getelementptr inbounds [18 x i8], [18 x i8]* %7, i64 0, i64 0
%24 = call i32 @unlink(i8* %23)
%25 = load i32, i32* %6
%26 = call i32 @close(i32 %25)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %33
28: ; preds = %19
%29 = load i32, i32* @stderr
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%31 = load i32, i32* @EXIT_FAILURE
%32 = call i32 @exit(i32 %31)
unreachable
33: ; preds = %19
%34 = call i32* (...) @tmpfile()
store i32* %34, i32** %8
%35 = load i32*, i32** %8
%36 = call i32 @fclose(i32* %35)
%37 = load i32, i32* @EXIT_SUCCESS
%38 = call i32 @exit(i32 %37)
unreachable
}

LLVM IR (-O2):
@__const.main.fileName = [18 x i8] c"/tmp/foobarXXXXXX\00"
@stderr = global i32 0
@.str = [17 x i8] c"error on mkstep\0A\00"
@EXIT_FAILURE = global i32 0
@stdout = global i32 0
@.str.1 = [30 x i8] c"%s is the generated filename\0A\00"
@.str.2 = [16 x i8] c"error on close\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [18 x i8]
%4 = getelementptr inbounds [18 x i8], [18 x i8]* %3, i64 0, i64 0
%5 = call i32 @mkstemp(i8* %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %12
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @EXIT_FAILURE
%11 = call i32 @exit(i32 %10)
unreachable
12: ; preds = %2
%13 = load i32, i32* @stdout
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%15 = call i32 @unlink(i8* %4)
%16 = call i32 @close(i32 %5)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %23
18: ; preds = %12
%19 = load i32, i32* @stderr
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %12
%24 = call i32* (...) @tmpfile()
%25 = call i32 @fclose(i32* %24)
%26 = load i32, i32* @EXIT_SUCCESS
%27 = call i32 @exit(i32 %26)
unreachable
}