#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 getBitAt(unsigned int, int);
int maxContinuousOnes(unsigned int bitmap, int *position) {
  int counter = 0;
  int max = 0;
  for (int i = 31; i >= 0; i--) {
    if (getBitAt(bitmap, i) == 1) {
      counter++;
    }
    if (getBitAt(bitmap, i) == 0) {
      counter = 0;
    }
    if (counter > max) {
      max = counter;
      *position = i;
    }
  }
  return max;
}


x86 assembly (clang, -O0):
<maxContinuousOnes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x1f,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     11a4 <maxContinuousOnes+0x94>
mov    -0x4(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1030 <getBitAt@plt>
cmp    $0x1,%eax
jne    115b <maxContinuousOnes+0x4b>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1030 <getBitAt@plt>
cmp    $0x0,%eax
jne    1176 <maxContinuousOnes+0x66>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jle    1191 <maxContinuousOnes+0x81>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    1196 <maxContinuousOnes+0x86>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1134 <maxContinuousOnes+0x24>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<maxContinuousOnes>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %edi,%r12d
xor    %r15d,%r15d
mov    $0x1f,%ebx
xor    %ebp,%ebp
jmp    1135 <maxContinuousOnes+0x25>
nopw   0x0(%rax,%rax,1)
add    $0xffffffff,%ebx
jae    1165 <maxContinuousOnes+0x55>
mov    %r12d,%edi
mov    %ebx,%esi
call   1030 <getBitAt@plt>
xor    %ecx,%ecx
cmp    $0x1,%eax
sete   %cl
add    %ecx,%ebp
mov    %r12d,%edi
mov    %ebx,%esi
call   1030 <getBitAt@plt>
test   %eax,%eax
cmove  %eax,%ebp
cmp    %r15d,%ebp
jle    1130 <maxContinuousOnes+0x20>
mov    %ebx,(%r14)
mov    %ebp,%r15d
jmp    1130 <maxContinuousOnes+0x20>
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @maxContinuousOnes(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i32* %1, i32** %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 31, i32* %7
br label %8
8: ; preds = %34, %2
%9 = load i32, i32* %7
%10 = icmp sge i32 %9, 0
br i1 %10, label %11, label %37
11: ; preds = %8
%12 = load i32, i32* %3
%13 = load i32, i32* %7
%14 = call i32 @getBitAt(i32 %12, i32 %13)
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = load i32, i32* %5
%18 = add nsw i32 %17, 1
store i32 %18, i32* %5
br label %19
19: ; preds = %16, %11
%20 = load i32, i32* %3
%21 = load i32, i32* %7
%22 = call i32 @getBitAt(i32 %20, i32 %21)
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %19
store i32 0, i32* %5
br label %25
25: ; preds = %24, %19
%26 = load i32, i32* %5
%27 = load i32, i32* %6
%28 = icmp sgt i32 %26, %27
br i1 %28, label %29, label %33
29: ; preds = %25
%30 = load i32, i32* %5
store i32 %30, i32* %6
%31 = load i32, i32* %7
%32 = load i32*, i32** %4
store i32 %31, i32* %32
br label %33
33: ; preds = %29, %25
br label %34
34: ; preds = %33
%35 = load i32, i32* %7
%36 = add nsw i32 %35, -1
store i32 %36, i32* %7
br label %8
37: ; preds = %8
%38 = load i32, i32* %6
ret i32 %38
}

LLVM IR (-O2):
define i32 @maxContinuousOnes(i32 %0, i32* nocapture writeonly %1) {
br label %4
3: ; preds = %17
ret i32 %18
4: ; preds = %2, %17
%5 = phi i32 [ 31, %2 ], [ %19, %17 ]
%6 = phi i32 [ 0, %2 ], [ %18, %17 ]
%7 = phi i32 [ 0, %2 ], [ %14, %17 ]
%8 = tail call i32 @getBitAt(i32 %0, i32 %5)
%9 = icmp eq i32 %8, 1
%10 = zext i1 %9 to i32
%11 = add nsw i32 %7, %10
%12 = tail call i32 @getBitAt(i32 %0, i32 %5)
%13 = icmp eq i32 %12, 0
%14 = select i1 %13, i32 0, i32 %11
%15 = icmp sgt i32 %14, %6
br i1 %15, label %16, label %17
16: ; preds = %4
store i32 %5, i32* %1
br label %17
17: ; preds = %4, %16
%18 = phi i32 [ %14, %16 ], [ %6, %4 ]
%19 = add nsw i32 %5, -1
%20 = icmp eq i32 %5, 0
br i1 %20, label %3, label %4
}