#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
char *tempnam(char *, char *);
void main(void) {
  FILE *stream;
  int i;
  char *name;
  for (i = 1; i <= 10; i++) {
    if ((name = tempnam("\\tmp", "wow")) == NULL)
      perror("tempnam couldn't create name");
    else {
      printf("Creating %s\n", name);
      if ((stream = fopen(name, "wb")) == NULL)
        perror("Could not open temporary file\n");
      else
        fclose(stream);
    }
    free(name);
  }
  printf("Warning: temp files not deleted.\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x1,-0xc(%rbp)
cmpl   $0xa,-0xc(%rbp)
jg     1211 <main+0xb1>
lea    0xe80(%rip),%rdi
lea    0xe7e(%rip),%rsi
call   1060 <tempnam@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11ab <main+0x4b>
lea    0xe68(%rip),%rdi
call   1080 <perror@plt>
jmp    11fa <main+0x9a>
mov    -0x18(%rbp),%rsi
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
lea    0xe6b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
jne    11ec <main+0x8c>
lea    0xe54(%rip),%rdi
call   1080 <perror@plt>
jmp    11f5 <main+0x95>
mov    -0x8(%rbp),%rdi
call   1040 <fclose@plt>
jmp    11fa <main+0x9a>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    116f <main+0xf>
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0xa,%ebp
lea    0xe79(%rip),%r14
lea    0xe77(%rip),%rbx
lea    0xe91(%rip),%r12
lea    0xe97(%rip),%r13
jmp    11b5 <main+0x45>
xchg   %ax,%ax
mov    %rax,%rdi
call   1050 <fclose@plt>
mov    %r15,%rdi
call   1030 <free@plt>
add    $0xffffffff,%ebp
je     1201 <main+0x91>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <tempnam@plt>
mov    %rax,%r15
test   %rax,%rax
je     11f3 <main+0x83>
mov    %r12,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   1080 <fopen@plt>
test   %rax,%rax
jne    11a0 <main+0x30>
lea    0xe4a(%rip),%rdi
call   1090 <perror@plt>
jmp    11a8 <main+0x38>
lea    0xe0f(%rip),%rdi
call   1090 <perror@plt>
jmp    11a8 <main+0x38>
lea    0xe4d(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <puts@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"\\tmp\00"
@.str.1 = [4 x i8] c"wow\00"
@.str.2 = [29 x i8] c"tempnam couldn't create name\00"
@.str.3 = [13 x i8] c"Creating %s\0A\00"
@.str.4 = [3 x i8] c"wb\00"
@.str.5 = [31 x i8] c"Could not open temporary file\0A\00"
@.str.6 = [34 x i8] c"Warning: temp files not deleted.\0A\00"
define void @main() {
%1 = alloca i32*
%2 = alloca i32
%3 = alloca i8*
store i32 1, i32* %2
br label %4
4: ; preds = %27, %0
%5 = load i32, i32* %2
%6 = icmp sle i32 %5, 10
br i1 %6, label %7, label %30
7: ; preds = %4
%8 = call i8* @tempnam(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store i8* %8, i8** %3
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %24
12: ; preds = %7
%13 = load i8*, i8** %3
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %13)
%15 = load i8*, i8** %3
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %16, i32** %1
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %20
18: ; preds = %12
%19 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0))
br label %23
20: ; preds = %12
%21 = load i32*, i32** %1
%22 = call i32 @fclose(i32* %21)
br label %23
23: ; preds = %20, %18
br label %24
24: ; preds = %23, %10
%25 = load i8*, i8** %3
%26 = call i32 @free(i8* %25)
br label %27
27: ; preds = %24
%28 = load i32, i32* %2
%29 = add nsw i32 %28, 1
store i32 %29, i32* %2
br label %4
30: ; preds = %4
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"\\tmp\00"
@.str.1 = [4 x i8] c"wow\00"
@.str.2 = [29 x i8] c"tempnam couldn't create name\00"
@.str.3 = [13 x i8] c"Creating %s\0A\00"
@.str.4 = [3 x i8] c"wb\00"
@.str.5 = [31 x i8] c"Could not open temporary file\0A\00"
@str = [33 x i8] c"Warning: temp files not deleted.\00"
define void @main() {
br label %1
1: ; preds = %0, %15
%2 = phi i32 [ 1, %0 ], [ %17, %15 ]
%3 = tail call i8* @tempnam(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %15
7: ; preds = %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %3)
%9 = tail call i32* @fopen(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = tail call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0))
br label %15
13: ; preds = %7
%14 = tail call i32 @fclose(i32* %9)
br label %15
15: ; preds = %11, %13, %5
%16 = tail call i32 @free(i8* %3)
%17 = add nuw nsw i32 %2, 1
%18 = icmp eq i32 %17, 11
br i1 %18, label %19, label %1
19: ; preds = %15
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
ret void
}