#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 int32_t;

/* Variables and functions */
scalar_t__ FileExists(char *);
scalar_t__ pow(int, int);
int /*<<< orphan*/ sprintf(char *, char *, char *, int, int, char *);
int32_t GetBIFMaximumBin(char *prefix, int32_t indexNumber) {
  int32_t curExp = 0;
  char bifName[2048] = "\0";
  while (1) {
    sprintf(bifName, "%s.%d.%d.%s", prefix, indexNumber, (int)pow(4, curExp),
            "bif");
    if (0 == FileExists(bifName)) {
      break;
    }
    curExp++;
  }
  if (0 == curExp) {
    return 0;
  }
  return (int)pow(4, curExp - 1);
}


x86 assembly (clang, -O0):
<GetBIFMaximumBin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
lea    -0x820(%rbp),%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1030 <memset@plt>
lea    -0x820(%rbp),%rax
mov    %rax,-0x838(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x830(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x824(%rbp)
mov    -0x18(%rbp),%esi
mov    $0x4,%edi
call   1040 <pow@plt>
mov    -0x838(%rbp),%rdi
mov    -0x830(%rbp),%rdx
mov    -0x824(%rbp),%ecx
mov    %eax,%r8d
lea    0xe47(%rip),%rsi
lea    0xe4c(%rip),%r9
call   1050 <sprintf@plt>
lea    -0x820(%rbp),%rdi
call   1060 <FileExists@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    11e4 <GetBIFMaximumBin+0xa4>
jmp    11f2 <GetBIFMaximumBin+0xb2>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    116c <GetBIFMaximumBin+0x2c>
xor    %eax,%eax
cmp    -0x18(%rbp),%eax
jne    1209 <GetBIFMaximumBin+0xc9>
movl   $0x0,-0x4(%rbp)
jmp    121c <GetBIFMaximumBin+0xdc>
mov    -0x18(%rbp),%esi
sub    $0x1,%esi
mov    $0x4,%edi
call   1040 <pow@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetBIFMaximumBin>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x808,%rsp
mov    %esi,%r14d
mov    %rdi,%r15
mov    %rsp,%rbp
xor    %ebx,%ebx
mov    $0x800,%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   1030 <memset@plt>
lea    0xe8e(%rip),%r12
lea    0xe93(%rip),%r13
nopl   0x0(%rax)
mov    $0x4,%edi
mov    %ebx,%esi
call   1040 <pow@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %r14d,%ecx
mov    %eax,%r8d
mov    %r13,%r9
call   1050 <sprintf@plt>
mov    %rbp,%rdi
call   1060 <FileExists@plt>
add    $0x1,%ebx
test   %rax,%rax
jne    1180 <GetBIFMaximumBin+0x40>
xor    %eax,%eax
cmp    $0x1,%ebx
je     11c9 <GetBIFMaximumBin+0x89>
add    $0xfffffffe,%ebx
mov    $0x4,%edi
mov    %ebx,%esi
call   1040 <pow@plt>
add    $0x808,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"%s.%d.%d.%s\00"
@.str.1 = [4 x i8] c"bif\00"
define i32 @GetBIFMaximumBin(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca [2048 x i8]
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 0, i32* %6
%8 = bitcast [2048 x i8]* %7 to i8*
br label %9
9: ; preds = %2, %21
%10 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%11 = load i8*, i8** %4
%12 = load i32, i32* %5
%13 = load i32, i32* %6
%14 = call i64 @pow(i32 4, i32 %13)
%15 = trunc i64 %14 to i32
%16 = call i32 @sprintf(i8* %10, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %11, i32 %12, i32 %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%17 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%18 = call i64 @FileExists(i8* %17)
%19 = icmp eq i64 0, %18
br i1 %19, label %20, label %21
20: ; preds = %9
br label %24
21: ; preds = %9
%22 = load i32, i32* %6
%23 = add nsw i32 %22, 1
store i32 %23, i32* %6
br label %9
24: ; preds = %20
%25 = load i32, i32* %6
%26 = icmp eq i32 0, %25
br i1 %26, label %27, label %28
27: ; preds = %24
store i32 0, i32* %3
br label %33
28: ; preds = %24
%29 = load i32, i32* %6
%30 = sub nsw i32 %29, 1
%31 = call i64 @pow(i32 4, i32 %30)
%32 = trunc i64 %31 to i32
store i32 %32, i32* %3
br label %33
33: ; preds = %28, %27
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
@.str = [12 x i8] c"%s.%d.%d.%s\00"
@.str.1 = [4 x i8] c"bif\00"
define i32 @GetBIFMaximumBin(i8* %0, i32 %1) {
%3 = alloca [2048 x i8]
%4 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
br label %5
5: ; preds = %5, %2
%6 = phi i32 [ 0, %2 ], [ %12, %5 ]
%7 = call i64 @pow(i32 4, i32 %6)
%8 = trunc i64 %7 to i32
%9 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %1, i32 %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%10 = call i64 @FileExists(i8* %4)
%11 = icmp eq i64 %10, 0
%12 = add nuw nsw i32 %6, 1
br i1 %11, label %13, label %5
13: ; preds = %5
%14 = icmp eq i32 %6, 0
br i1 %14, label %19, label %15
15: ; preds = %13
%16 = add nsw i32 %6, -1
%17 = call i64 @pow(i32 4, i32 %16)
%18 = trunc i64 %17 to i32
br label %19
19: ; preds = %13, %15
%20 = phi i32 [ %18, %15 ], [ 0, %13 ]
ret i32 %20
}