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

/* Variables and functions */
int16_t norm_s(int16_t var1) {
  int16_t var_out;
  if (var1 == 0) {
    var_out = 0;
  } else {
    if (var1 == (int16_t)0xffff) {
      var_out = 15;
    } else {
      if (var1 < 0) {
        var1 = ~var1;
      }
      for (var_out = 0; var1 < 0x4000; var_out++) {
        var1 <<= 1;
      }
    }
  }
  return (var_out);
}


x86 assembly (clang, -O0):
<norm_s>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    111d <norm_s+0x1d>
movl   $0x0,-0x8(%rbp)
jmp    117e <norm_s+0x7e>
cmpl   $0xffff,-0x4(%rbp)
jne    1136 <norm_s+0x36>
movl   $0xf,-0x8(%rbp)
jmp    1179 <norm_s+0x79>
cmpl   $0x0,-0x4(%rbp)
jge    1149 <norm_s+0x49>
mov    -0x4(%rbp),%eax
xor    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x4000,-0x4(%rbp)
jge    1174 <norm_s+0x74>
mov    -0x4(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1150 <norm_s+0x50>
jmp    1179 <norm_s+0x79>
jmp    117e <norm_s+0x7e>
mov    -0x8(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<norm_s>:
mov    %edi,%eax
test   %edi,%edi
je     113d <norm_s+0x3d>
cmp    $0xffff,%eax
jne    1113 <norm_s+0x13>
mov    $0xf,%eax
ret
mov    %eax,%ecx
sar    $0x1f,%ecx
xor    %eax,%ecx
xor    %eax,%eax
cmp    $0x3fff,%ecx
jg     113d <norm_s+0x3d>
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
add    %ecx,%ecx
add    $0x1,%eax
cmp    $0x4000,%ecx
jl     1130 <norm_s+0x30>
ret

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

LLVM IR (-O2):
define i32 @norm_s(i32 %0) {
switch i32 %0, label %3 [
i32 0, label %13
i32 65535, label %2
]
2: ; preds = %1
br label %13
3: ; preds = %1
%4 = ashr i32 %0, 31
%5 = xor i32 %4, %0
%6 = icmp slt i32 %5, 16384
br i1 %6, label %7, label %13
7: ; preds = %3, %7
%8 = phi i32 [ %11, %7 ], [ 0, %3 ]
%9 = phi i32 [ %10, %7 ], [ %5, %3 ]
%10 = shl i32 %9, 1
%11 = add nuw nsw i32 %8, 1
%12 = icmp slt i32 %10, 16384
br i1 %12, label %7, label %13
13: ; preds = %7, %3, %1, %2
%14 = phi i32 [ 15, %2 ], [ %0, %1 ], [ 0, %3 ], [ %11, %7 ]
ret i32 %14
}