#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 */
scalar_t__ get_bit(int, int);
int longest_seq(int number) {
  int max_len = 0;
  int current_len = 0;
  for (int i = 0; i < 32; i++) {
    if (get_bit(number, i)) {
      current_len++;
    } else {
      if (current_len > max_len) {
        max_len = current_len;
      }
      current_len = 0;
    }
  }
  return max_len;
}


x86 assembly (clang, -O0):
<longest_seq>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x20,-0x10(%rbp)
jge    1189 <longest_seq+0x79>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1030 <get_bit@plt>
cmp    $0x0,%rax
je     115d <longest_seq+0x4d>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1176 <longest_seq+0x66>
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jle    116f <longest_seq+0x5f>
mov    -0xc(%rbp),%eax
mov    %eax,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
jmp    117b <longest_seq+0x6b>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1130 <longest_seq+0x20>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<longest_seq>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%r15d
xor    %r14d,%r14d
xor    %ebp,%ebp
xor    %ebx,%ebx
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %eax,%r12d
mov    %r15d,%edi
mov    %ebp,%esi
call   1030 <get_bit@plt>
lea    0x1(%rbx),%ecx
cmp    %r12d,%ebx
cmovle %r12d,%ebx
test   %rax,%rax
mov    %ebx,%eax
cmovne %r12d,%eax
cmove  %r14d,%ecx
add    $0x1,%ebp
mov    %ecx,%ebx
cmp    $0x20,%ebp
jne    1130 <longest_seq+0x20>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @longest_seq(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
br label %6
6: ; preds = %25, %1
%7 = load i32, i32* %5
%8 = icmp slt i32 %7, 32
br i1 %8, label %9, label %28
9: ; preds = %6
%10 = load i32, i32* %2
%11 = load i32, i32* %5
%12 = call i64 @get_bit(i32 %10, i32 %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = load i32, i32* %4
%16 = add nsw i32 %15, 1
store i32 %16, i32* %4
br label %24
17: ; preds = %9
%18 = load i32, i32* %4
%19 = load i32, i32* %3
%20 = icmp sgt i32 %18, %19
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = load i32, i32* %4
store i32 %22, i32* %3
br label %23
23: ; preds = %21, %17
store i32 0, i32* %4
br label %24
24: ; preds = %23, %14
br label %25
25: ; preds = %24
%26 = load i32, i32* %5
%27 = add nsw i32 %26, 1
store i32 %27, i32* %5
br label %6
28: ; preds = %6
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
define i32 @longest_seq(i32 %0) {
br label %3
2: ; preds = %3
ret i32 %12
3: ; preds = %1, %3
%4 = phi i32 [ 0, %1 ], [ %14, %3 ]
%5 = phi i32 [ 0, %1 ], [ %13, %3 ]
%6 = phi i32 [ 0, %1 ], [ %12, %3 ]
%7 = tail call i64 @get_bit(i32 %0, i32 %4)
%8 = icmp eq i64 %7, 0
%9 = add nsw i32 %5, 1
%10 = icmp sgt i32 %5, %6
%11 = select i1 %8, i1 %10, i1 false
%12 = select i1 %11, i32 %5, i32 %6
%13 = select i1 %8, i32 0, i32 %9
%14 = add nuw nsw i32 %4, 1
%15 = icmp eq i32 %14, 32
br i1 %15, label %2, label %3
}