#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*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, int);
int /*<<< orphan*/ stderr;
int FindTempFileName(char *filename) {
  FILE *fp;
  int i;
  for (i = 0; i < 100; i++) {
    sprintf(filename, "%s%d.tmp", "/tmp/wwwskruttget", i);
    if (!(fp = fopen(filename, "r")))
      break;
    fclose(fp);
  }
  if (!(fp = fopen(filename, "w"))) {
    fprintf(stderr, "Kan inte skriva på %s\n", filename);
    *filename = '\0';
    return 0;
  }
  fclose(fp);
  return 1;
}


x86 assembly (clang, -O0):
<FindTempFileName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x64,-0x1c(%rbp)
jge    11b1 <FindTempFileName+0x71>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%ecx
lea    0xe95(%rip),%rsi
lea    0xe97(%rip),%rdx
call   1060 <sprintf@plt>
mov    -0x10(%rbp),%rdi
lea    0xe99(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    119a <FindTempFileName+0x5a>
jmp    11b1 <FindTempFileName+0x71>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1153 <FindTempFileName+0x13>
mov    -0x10(%rbp),%rdi
lea    0xe61(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11fb <FindTempFileName+0xbb>
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe3c(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    120b <FindTempFileName+0xcb>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FindTempFileName>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%rbx
xor    %ebp,%ebp
lea    0xeac(%rip),%r14
lea    0xeae(%rip),%r15
lea    0xeb9(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %ebp,%ecx
call   1060 <sprintf@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11a0 <FindTempFileName+0x60>
mov    %rax,%rdi
call   1030 <fclose@plt>
add    $0x1,%ebp
cmp    $0x64,%ebp
jne    1170 <FindTempFileName+0x30>
lea    0xe76(%rip),%rsi
mov    %rbx,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     11c3 <FindTempFileName+0x83>
mov    %rax,%rdi
call   1030 <fclose@plt>
mov    $0x1,%eax
jmp    11e0 <FindTempFileName+0xa0>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
lea    0xe4c(%rip),%rsi
mov    %rbx,%rdx
call   1040 <fprintf@plt>
movb   $0x0,(%rbx)
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"%s%d.tmp\00"
@.str.1 = [18 x i8] c"/tmp/wwwskruttget\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.4 = [24 x i8] c"Kan inte skriva p\C3\A5 %s\0A\00"
define i32 @FindTempFileName(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %5
br label %6
6: ; preds = %20, %1
%7 = load i32, i32* %5
%8 = icmp slt i32 %7, 100
br i1 %8, label %9, label %23
9: ; preds = %6
%10 = load i8*, i8** %3
%11 = load i32, i32* %5
%12 = call i32 @sprintf(i8* %10, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = load i8*, i8** %3
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %14, i32** %4
%15 = icmp ne i32* %14, null
br i1 %15, label %17, label %16
16: ; preds = %9
br label %23
17: ; preds = %9
%18 = load i32*, i32** %4
%19 = call i32 @fclose(i32* %18)
br label %20
20: ; preds = %17
%21 = load i32, i32* %5
%22 = add nsw i32 %21, 1
store i32 %22, i32* %5
br label %6
23: ; preds = %16, %6
%24 = load i8*, i8** %3
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %25, i32** %4
%26 = icmp ne i32* %25, null
br i1 %26, label %32, label %27
27: ; preds = %23
%28 = load i32, i32* @stderr
%29 = load i8*, i8** %3
%30 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %29)
%31 = load i8*, i8** %3
store i8 0, i8* %31
store i32 0, i32* %2
br label %35
32: ; preds = %23
%33 = load i32*, i32** %4
%34 = call i32 @fclose(i32* %33)
store i32 1, i32* %2
br label %35
35: ; preds = %32, %27
%36 = load i32, i32* %2
ret i32 %36
}

LLVM IR (-O2):
@.str = [9 x i8] c"%s%d.tmp\00"
@.str.1 = [18 x i8] c"/tmp/wwwskruttget\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.4 = [24 x i8] c"Kan inte skriva p\C3\A5 %s\0A\00"
define i32 @FindTempFileName(i8* %0) {
br label %2
2: ; preds = %1, %7
%3 = phi i32 [ 0, %1 ], [ %9, %7 ]
%4 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %3)
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %11, label %7
7: ; preds = %2
%8 = tail call i32 @fclose(i32* %5)
%9 = add nuw nsw i32 %3, 1
%10 = icmp eq i32 %9, 100
br i1 %10, label %11, label %2
11: ; preds = %2, %7
%12 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %0)
store i8 0, i8* %0
br label %19
17: ; preds = %11
%18 = tail call i32 @fclose(i32* %12)
br label %19
19: ; preds = %17, %14
%20 = phi i32 [ 1, %17 ], [ 0, %14 ]
ret i32 %20
}