#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_bbc_name(int num, char *dir, char *out) {
  FILE *f;
  if (num == 0) {
    sprintf(out, "%sP.Title", dir);
    f = fopen(out, "rb");
    if (f != NULL) {
      fclose(f);
      return;
    }
    sprintf(out, "%stitle", dir);
  } else {
    sprintf(out, "%sP.Pic%d", dir, num);
    f = fopen(out, "rb");
    if (f != NULL) {
      fclose(f);
      return;
    }
    sprintf(out, "%spic%d", dir, num);
  }
}


x86 assembly (clang, -O0):
<bitmap_bbc_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    11ab <bitmap_bbc_name+0x7b>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xea4(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xe9c(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1190 <bitmap_bbc_name+0x60>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
jmp    120a <bitmap_bbc_name+0xda>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe6e(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
jmp    120a <bitmap_bbc_name+0xda>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x4(%rbp),%ecx
lea    0xe58(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xe3b(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11f1 <bitmap_bbc_name+0xc1>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
jmp    120a <bitmap_bbc_name+0xda>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x4(%rbp),%ecx
lea    0xe1c(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bitmap_bbc_name>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%r14
test   %edi,%edi
je     1184 <bitmap_bbc_name+0x54>
mov    %edi,%ebp
lea    0xece(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
mov    %ebp,%ecx
xor    %eax,%eax
call   1050 <sprintf@plt>
lea    0xead(%rip),%rsi
mov    %rbx,%rdi
call   1040 <fopen@plt>
test   %rax,%rax
jne    11ac <bitmap_bbc_name+0x7c>
lea    0xeae(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
mov    %ebp,%ecx
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <sprintf@plt>
lea    0xe75(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <sprintf@plt>
lea    0xe6b(%rip),%rsi
mov    %rbx,%rdi
call   1040 <fopen@plt>
test   %rax,%rax
je     11b8 <bitmap_bbc_name+0x88>
mov    %rax,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <fclose@plt>
lea    0xe4e(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <sprintf@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"%sP.Title\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [8 x i8] c"%stitle\00"
@.str.3 = [10 x i8] c"%sP.Pic%d\00"
@.str.4 = [8 x i8] c"%spic%d\00"
define void @bitmap_bbc_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 %25
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 ([10 x i8], [10 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 %42
21: ; preds = %10
%22 = load i8*, i8** %6
%23 = load i8*, i8** %5
%24 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %22, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %23)
br label %42
25: ; preds = %3
%26 = load i8*, i8** %6
%27 = load i8*, i8** %5
%28 = load i32, i32* %4
%29 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %26, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %27, i32 %28)
%30 = load i8*, i8** %6
%31 = call i32* @fopen(i8* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %31, i32** %7
%32 = load i32*, i32** %7
%33 = icmp ne i32* %32, null
br i1 %33, label %34, label %37
34: ; preds = %25
%35 = load i32*, i32** %7
%36 = call i32 @fclose(i32* %35)
br label %42
37: ; preds = %25
%38 = load i8*, i8** %6
%39 = load i8*, i8** %5
%40 = load i32, i32* %4
%41 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %38, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* %39, i32 %40)
br label %42
42: ; preds = %18, %34, %37, %21
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"%sP.Title\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [8 x i8] c"%stitle\00"
@.str.3 = [10 x i8] c"%sP.Pic%d\00"
@.str.4 = [8 x i8] c"%spic%d\00"
define void @bitmap_bbc_name(i32 %0, i8* %1, i8* nocapture %2) {
%4 = icmp eq i32 %0, 0
br i1 %4, label %5, label %13
5: ; preds = %3
%6 = tail call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %2, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 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 %21
11: ; preds = %5
%12 = tail call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %2, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %1)
br label %21
13: ; preds = %3
%14 = tail call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %2, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %1, i32 %0)
%15 = tail call i32* @fopen(i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %19, label %17
17: ; preds = %13
%18 = tail call i32 @fclose(i32* %15)
br label %21
19: ; preds = %13
%20 = tail call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %2, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* %1, i32 %0)
br label %21
21: ; preds = %11, %19, %17, %9
ret void
}