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

/* Variables and functions */
int /*<<< orphan*/ assert(int);
uint32_t norm32(uint32_t x, int *e, int bit) {
  assert((x & ~((2 << bit) - 1)) == 0);
  if (!x)
    return 0;
  while (!(x & 1 << bit)) {
    x <<= 1;
    (*e)--;
  }
  return x;
}


x86 assembly (clang, -O0):
<norm32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    -0x14(%rbp),%ecx
mov    $0x2,%edx
shl    %cl,%edx
mov    %edx,%ecx
sub    $0x1,%ecx
xor    $0xffffffff,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
cmpl   $0x0,-0x8(%rbp)
jne    115f <norm32+0x4f>
movl   $0x0,-0x4(%rbp)
jmp    11a9 <norm32+0x99>
jmp    1164 <norm32+0x54>
mov    -0x8(%rbp),%eax
mov    -0x14(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    118a <norm32+0x7a>
jmp    11a3 <norm32+0x93>
mov    -0x8(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0xffffffff,%ecx
mov    %ecx,(%rax)
jmp    1164 <norm32+0x54>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<norm32>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %edi,%ebx
mov    %edi,%eax
mov    %ebp,%ecx
shr    %cl,%eax
mov    %rsi,%r14
xor    %edi,%edi
test   $0xfffffffe,%eax
sete   %dil
call   1030 <assert@plt>
test   %ebx,%ebx
je     115e <norm32+0x4e>
mov    $0x1,%eax
mov    %ebp,%ecx
shl    %cl,%eax
bt     %ebp,%ebx
jb     1160 <norm32+0x50>
mov    (%r14),%ecx
cs nopw 0x0(%rax,%rax,1)
add    %ebx,%ebx
add    $0xffffffff,%ecx
test   %eax,%ebx
je     1150 <norm32+0x40>
mov    %ecx,(%r14)
jmp    1160 <norm32+0x50>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @norm32(i32 %0, i32* nocapture %1, i32 %2) {
%4 = shl i32 -2, %2
%5 = and i32 %4, %0
%6 = icmp eq i32 %5, 0
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = icmp eq i32 %0, 0
br i1 %9, label %24, label %10
10: ; preds = %3
%11 = shl nuw i32 1, %2
%12 = and i32 %11, %0
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %24
14: ; preds = %10
%15 = load i32, i32* %1
br label %16
16: ; preds = %14, %16
%17 = phi i32 [ %15, %14 ], [ %20, %16 ]
%18 = phi i32 [ %0, %14 ], [ %19, %16 ]
%19 = shl i32 %18, 1
%20 = add nsw i32 %17, -1
%21 = and i32 %19, %11
%22 = icmp eq i32 %21, 0
br i1 %22, label %16, label %23
23: ; preds = %16
store i32 %20, i32* %1
br label %24
24: ; preds = %10, %23, %3
%25 = phi i32 [ 0, %3 ], [ %19, %23 ], [ %0, %10 ]
ret i32 %25
}