#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 /*<<< orphan*/ _exit(int);
void foo(unsigned int n) {
  int i, j = -1;
  for (i = 0; i < 10 && j < 0; i++) {
    if ((1UL << i) == n)
      j = i;
  }
  if (j < 0)
    _exit(-1);
}


x86 assembly (clang, -O0):
<foo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0xffffffff,-0xc(%rbp)
movl   $0x0,-0x8(%rbp)
xor    %eax,%eax
cmpl   $0xa,-0x8(%rbp)
mov    %al,-0xd(%rbp)
jge    1142 <foo+0x32>
cmpl   $0x0,-0xc(%rbp)
setl   %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    1152 <foo+0x42>
jmp    1184 <foo+0x74>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
mov    $0x1,%eax
shl    %cl,%rax
mov    -0x4(%rbp),%ecx
cmp    %rcx,%rax
jne    1171 <foo+0x61>
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1176 <foo+0x66>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1129 <foo+0x19>
cmpl   $0x0,-0xc(%rbp)
jge    1198 <foo+0x88>
mov    $0xffffffff,%edi
call   1030 <_exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<foo>:
mov    %edi,%eax
mov    $0xffffffff,%edx
xor    %ecx,%ecx
nopl   0x0(%rax)
mov    %edx,%esi
mov    $0x1,%edx
shl    %cl,%rdx
cmp    %rax,%rdx
mov    %ecx,%edx
cmovne %esi,%edx
cmp    $0x8,%rcx
ja     1140 <foo+0x30>
add    $0x1,%rcx
test   %edx,%edx
js     1120 <foo+0x10>
test   %edx,%edx
js     1145 <foo+0x35>
ret
push   %rax
mov    $0xffffffff,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
define void @foo(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 -1, i32* %4
store i32 0, i32* %3
br label %5
5: ; preds = %23, %1
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 10
br i1 %7, label %8, label %11
8: ; preds = %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 0
br label %11
11: ; preds = %8, %5
%12 = phi i1 [ false, %5 ], [ %10, %8 ]
br i1 %12, label %13, label %26
13: ; preds = %11
%14 = load i32, i32* %3
%15 = zext i32 %14 to i64
%16 = shl i64 1, %15
%17 = load i32, i32* %2
%18 = zext i32 %17 to i64
%19 = icmp eq i64 %16, %18
br i1 %19, label %20, label %22
20: ; preds = %13
%21 = load i32, i32* %3
store i32 %21, i32* %4
br label %22
22: ; preds = %20, %13
br label %23
23: ; preds = %22
%24 = load i32, i32* %3
%25 = add nsw i32 %24, 1
store i32 %25, i32* %3
br label %5
26: ; preds = %11
%27 = load i32, i32* %4
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = call i32 @_exit(i32 -1)
unreachable
31: ; preds = %26
ret void
}

LLVM IR (-O2):
define void @foo(i32 %0) {
%2 = zext i32 %0 to i64
br label %3
3: ; preds = %1, %3
%4 = phi i64 [ 0, %1 ], [ %10, %3 ]
%5 = phi i32 [ -1, %1 ], [ %9, %3 ]
%6 = shl nuw nsw i64 1, %4
%7 = icmp eq i64 %6, %2
%8 = trunc i64 %4 to i32
%9 = select i1 %7, i32 %8, i32 %5
%10 = add nuw nsw i64 %4, 1
%11 = icmp ult i64 %4, 9
%12 = icmp slt i32 %9, 0
%13 = select i1 %11, i1 %12, i1 false
br i1 %13, label %3, label %14
14: ; preds = %3
br i1 %12, label %15, label %17
15: ; preds = %14
%16 = tail call i32 @_exit(i32 -1)
unreachable
17: ; preds = %14
ret void
}