#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 */

/* Variables and functions */
int getAbsoluteBlockNumber(unsigned long);
unsigned long getNextBlockOffset(unsigned long);
scalar_t__ isBadBlock(unsigned long);
int /*<<< orphan*/ printf(char *, int);
int getNextCleanBlock(unsigned long offset) {
  offset = getNextBlockOffset(offset);
  if (!isBadBlock(offset)) {
    return offset;
  } else {
    while (isBadBlock(offset)) {
      printf("DEBUG: block %d is ALSO BAD, skipping to next block.\n",
             getAbsoluteBlockNumber(offset));
      offset = getNextBlockOffset(offset);
    }
    return offset;
  }
}


x86 assembly (clang, -O0):
<getNextCleanBlock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <getNextBlockOffset@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <isBadBlock@plt>
cmp    $0x0,%rax
jne    1178 <getNextCleanBlock+0x38>
mov    -0x10(%rbp),%rax
mov    %eax,-0x4(%rbp)
jmp    11c0 <getNextCleanBlock+0x80>
jmp    117d <getNextCleanBlock+0x3d>
mov    -0x10(%rbp),%rdi
call   1060 <isBadBlock@plt>
cmp    $0x0,%rax
je     11b9 <getNextCleanBlock+0x79>
mov    -0x10(%rbp),%rdi
call   1030 <getAbsoluteBlockNumber@plt>
mov    %eax,%esi
lea    0xe5e(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <getNextBlockOffset@plt>
mov    %rax,-0x10(%rbp)
jmp    117d <getNextCleanBlock+0x3d>
mov    -0x10(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getNextCleanBlock>:
push   %r14
push   %rbx
push   %rax
call   1050 <getNextBlockOffset@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <isBadBlock@plt>
test   %rax,%rax
je     119a <getNextCleanBlock+0x5a>
mov    %rbx,%rdi
call   1060 <isBadBlock@plt>
test   %rax,%rax
je     119a <getNextCleanBlock+0x5a>
lea    0xe93(%rip),%r14
nopl   (%rax)
mov    %rbx,%rdi
call   1030 <getAbsoluteBlockNumber@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1050 <getNextBlockOffset@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <isBadBlock@plt>
test   %rax,%rax
jne    1170 <getNextCleanBlock+0x30>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [54 x i8] c"DEBUG: block %d is ALSO BAD, skipping to next block.\0A\00"
define i32 @getNextCleanBlock(i64 %0) {
%2 = alloca i32
%3 = alloca i64
store i64 %0, i64* %3
%4 = load i64, i64* %3
%5 = call i64 @getNextBlockOffset(i64 %4)
store i64 %5, i64* %3
%6 = load i64, i64* %3
%7 = call i64 @isBadBlock(i64 %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %1
%10 = load i64, i64* %3
%11 = trunc i64 %10 to i32
store i32 %11, i32* %2
br label %26
12: ; preds = %1
br label %13
13: ; preds = %17, %12
%14 = load i64, i64* %3
%15 = call i64 @isBadBlock(i64 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %13
%18 = load i64, i64* %3
%19 = call i32 @getAbsoluteBlockNumber(i64 %18)
%20 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = load i64, i64* %3
%22 = call i64 @getNextBlockOffset(i64 %21)
store i64 %22, i64* %3
br label %13
23: ; preds = %13
%24 = load i64, i64* %3
%25 = trunc i64 %24 to i32
store i32 %25, i32* %2
br label %26
26: ; preds = %23, %9
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
@.str = [54 x i8] c"DEBUG: block %d is ALSO BAD, skipping to next block.\0A\00"
define i32 @getNextCleanBlock(i64 %0) {
%2 = tail call i64 @getNextBlockOffset(i64 %0)
%3 = tail call i64 @isBadBlock(i64 %2)
%4 = icmp eq i64 %3, 0
br i1 %4, label %15, label %5
5: ; preds = %1
%6 = tail call i64 @isBadBlock(i64 %2)
%7 = icmp eq i64 %6, 0
br i1 %7, label %15, label %8
8: ; preds = %5, %8
%9 = phi i64 [ %12, %8 ], [ %2, %5 ]
%10 = tail call i32 @getAbsoluteBlockNumber(i64 %9)
%11 = tail call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = tail call i64 @getNextBlockOffset(i64 %9)
%13 = tail call i64 @isBadBlock(i64 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %8
15: ; preds = %8, %5, %1
%16 = phi i64 [ %2, %1 ], [ %2, %5 ], [ %12, %8 ]
%17 = trunc i64 %16 to i32
ret i32 %17
}