#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*/ sprintf(char *, char *, char *, ...);
void bitmap_noext_name(int num, char *dir, char *out) {
  if (num == 0) {
    FILE *f;
    sprintf(out, "%stitle", dir);
    f = fopen(out, "rb");
    if (f != NULL) {
      fclose(f);
      return;
    } else
      num = 30;
  }
  sprintf(out, "%s%d", dir, num);
}


x86 assembly (clang, -O0):
<bitmap_noext_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    119c <bitmap_noext_name+0x6c>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xea4(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xe9a(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1190 <bitmap_noext_name+0x60>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
jmp    11b5 <bitmap_noext_name+0x85>
movl   $0x1e,-0x4(%rbp)
jmp    119c <bitmap_noext_name+0x6c>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x4(%rbp),%ecx
lea    0xe5d(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bitmap_noext_name>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %edi,%ecx
test   %edi,%edi
je     115b <bitmap_noext_name+0x2b>
lea    0xec4(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <sprintf@plt>
lea    0xe9e(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <sprintf@plt>
lea    0xe92(%rip),%rsi
mov    %rbx,%rdi
call   1040 <fopen@plt>
test   %rax,%rax
je     1192 <bitmap_noext_name+0x62>
mov    %rax,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <fclose@plt>
mov    $0x1e,%ecx
jmp    1140 <bitmap_noext_name+0x10>

LLVM IR (-O0):
@.str = [8 x i8] c"%stitle\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [5 x i8] c"%s%d\00"
define void @bitmap_noext_name(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
store i32 %0, i32* %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %23
10: ; preds = %3
%11 = load i8*, i8** %6
%12 = load i8*, i8** %5
%13 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %11, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = load i8*, i8** %6
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %15, i32** %7
%16 = load i32*, i32** %7
%17 = icmp ne i32* %16, null
br i1 %17, label %18, label %21
18: ; preds = %10
%19 = load i32*, i32** %7
%20 = call i32 @fclose(i32* %19)
br label %28
21: ; preds = %10
store i32 30, i32* %4
br label %22
22: ; preds = %21
br label %23
23: ; preds = %22, %3
%24 = load i8*, i8** %6
%25 = load i8*, i8** %5
%26 = load i32, i32* %4
%27 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %25, i32 %26)
br label %28
28: ; preds = %23, %18
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"%stitle\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [5 x i8] c"%s%d\00"
define void @bitmap_noext_name(i32 %0, i8* %1, i8* nocapture %2) {
%4 = icmp eq i32 %0, 0
br i1 %4, label %5, label %11
5: ; preds = %3
%6 = tail call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %2, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %1)
%7 = tail call i32* @fopen(i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %11, label %9
9: ; preds = %5
%10 = tail call i32 @fclose(i32* %7)
br label %14
11: ; preds = %5, %3
%12 = phi i32 [ %0, %3 ], [ 30, %5 ]
%13 = tail call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %2, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %1, i32 %12)
br label %14
14: ; preds = %9, %11
ret void
}