#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);
int bsr(int);
void compute_dist_icf_code(uint32_t dist, uint32_t *code,
                           uint32_t *extra_bits) {
  uint32_t msb;
  uint32_t num_extra_bits;
  dist -= 1;
  msb = bsr(dist);
  assert(msb >= 1);
  num_extra_bits = msb - 2;
  *extra_bits = dist & ((1 << num_extra_bits) - 1);
  dist >>= num_extra_bits;
  *code = dist + 2 * num_extra_bits;
  assert(*code < 30);
}


x86 assembly (clang, -O0):
<compute_dist_icf_code>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <bsr@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x1c(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x20(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    -0x24(%rbp),%ecx
sub    $0x1,%eax
and    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%ecx
mov    -0x4(%rbp),%eax
sar    %cl,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%ecx
mov    -0x20(%rbp),%eax
shl    $0x1,%eax
add    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
cmpl   $0x1e,(%rax)
setl   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compute_dist_icf_code>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
mov    %edi,%ebx
add    $0xffffffff,%ebx
mov    %ebx,%edi
call   1040 <bsr@plt>
mov    %eax,%r12d
xor    %edi,%edi
test   %eax,%eax
setg   %dil
call   1030 <assert@plt>
lea    -0x2(%r12),%ecx
mov    $0xffffffff,%eax
shl    %cl,%eax
not    %eax
and    %ebx,%eax
mov    %eax,(%r15)
sar    %cl,%ebx
lea    (%rbx,%r12,2),%eax
add    $0xfffffffc,%eax
mov    %eax,(%r14)
xor    %edi,%edi
cmp    $0x1e,%eax
setl   %dil
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <assert@plt>

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

LLVM IR (-O2):
define void @compute_dist_icf_code(i32 %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2) {
%4 = add nsw i32 %0, -1
%5 = tail call i32 @bsr(i32 %4)
%6 = icmp sgt i32 %5, 0
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = add nsw i32 %5, -2
%10 = shl nsw i32 -1, %9
%11 = xor i32 %10, -1
%12 = and i32 %4, %11
store i32 %12, i32* %2
%13 = ashr i32 %4, %9
%14 = shl nsw i32 %9, 1
%15 = add nsw i32 %13, %14
store i32 %15, i32* %1
%16 = icmp slt i32 %15, 30
%17 = zext i1 %16 to i32
%18 = tail call i32 @assert(i32 %17)
ret void
}