#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*/ *fdopen(int, char *);
int mkstemp(char *);
int /*<<< orphan*/ strcpy(char *, char *);
FILE *randomfile(char *filename, int retry) {
  int i, fd;
  strcpy(filename, "/tmp/kadimus-XXXXXX");
  for (i = 0; i <= retry; i++) {
    if ((fd = mkstemp(filename)) != -1) {
      return fdopen(fd, "w");
    }
  }
  return NULL;
}


x86 assembly (clang, -O0):
<randomfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb6(%rip),%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     11a2 <randomfile+0x72>
mov    -0x10(%rbp),%rdi
call   1040 <mkstemp@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
je     118f <randomfile+0x5f>
mov    -0x1c(%rbp),%edi
lea    0xe93(%rip),%rsi
call   1050 <fdopen@plt>
mov    %rax,-0x8(%rbp)
jmp    11aa <randomfile+0x7a>
jmp    1194 <randomfile+0x64>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1156 <randomfile+0x26>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randomfile>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r14
lea    0xec0(%rip),%rsi
call   1030 <strcpy@plt>
test   %ebx,%ebx
js     1162 <randomfile+0x32>
add    $0x1,%ebx
nopl   0x0(%rax)
mov    %r14,%rdi
call   1040 <mkstemp@plt>
cmp    $0xffffffff,%eax
jne    116c <randomfile+0x3c>
add    $0xffffffff,%ebx
jne    1150 <randomfile+0x20>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xea1(%rip),%rsi
mov    %eax,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <fdopen@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"/tmp/kadimus-XXXXXX\00"
@.str.1 = [2 x i8] c"w\00"
define i32* @randomfile(i8* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%8 = load i8*, i8** %4
%9 = call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %6
br label %10
10: ; preds = %22, %2
%11 = load i32, i32* %6
%12 = load i32, i32* %5
%13 = icmp sle i32 %11, %12
br i1 %13, label %14, label %25
14: ; preds = %10
%15 = load i8*, i8** %4
%16 = call i32 @mkstemp(i8* %15)
store i32 %16, i32* %7
%17 = icmp ne i32 %16, -1
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = load i32, i32* %7
%20 = call i32* @fdopen(i32 %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %3
br label %26
21: ; preds = %14
br label %22
22: ; preds = %21
%23 = load i32, i32* %6
%24 = add nsw i32 %23, 1
store i32 %24, i32* %6
br label %10
25: ; preds = %10
store i32* null, i32** %3
br label %26
26: ; preds = %25, %18
%27 = load i32*, i32** %3
ret i32* %27
}

LLVM IR (-O2):
@.str = [20 x i8] c"/tmp/kadimus-XXXXXX\00"
@.str.1 = [2 x i8] c"w\00"
define noalias i32* @randomfile(i8* %0, i32 %1) {
%3 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%4 = icmp slt i32 %1, 0
br i1 %4, label %14, label %8
5: ; preds = %8
%6 = add nuw i32 %9, 1
%7 = icmp eq i32 %9, %1
br i1 %7, label %14, label %8
8: ; preds = %2, %5
%9 = phi i32 [ %6, %5 ], [ 0, %2 ]
%10 = tail call i32 @mkstemp(i8* %0)
%11 = icmp eq i32 %10, -1
br i1 %11, label %5, label %12
12: ; preds = %8
%13 = tail call i32* @fdopen(i32 %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %5, %2, %12
%15 = phi i32* [ %13, %12 ], [ null, %2 ], [ null, %5 ]
ret i32* %15
}