#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 /*<<< orphan*/ compute_dist_icf_code(int, int *, int *);
void get_dist_icf_code(uint32_t dist, uint32_t *code, uint32_t *extra_bits) {
  assert(dist >= 1);
  assert(dist <= 32768);
  if (dist <= 2) {
    *code = dist - 1;
    *extra_bits = 0;
  } else {
    compute_dist_icf_code(dist, code, extra_bits);
  }
}


x86 assembly (clang, -O0):
<get_dist_icf_code>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpl   $0x1,-0x4(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
cmpl   $0x8000,-0x4(%rbp)
setle  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
cmpl   $0x2,-0x4(%rbp)
jg     117d <get_dist_icf_code+0x5d>
mov    -0x4(%rbp),%ecx
sub    $0x1,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
jmp    118d <get_dist_icf_code+0x6d>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <compute_dist_icf_code@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_dist_icf_code>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %edi,%edi
test   %ebp,%ebp
setg   %dil
call   1030 <assert@plt>
xor    %edi,%edi
cmp    $0x8001,%ebp
setl   %dil
call   1030 <assert@plt>
cmp    $0x2,%ebp
jg     1160 <get_dist_icf_code+0x40>
add    $0xffffffff,%ebp
mov    %ebp,(%rbx)
movl   $0x0,(%r14)
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <compute_dist_icf_code@plt>

LLVM IR (-O0):
define void @get_dist_icf_code(i32 %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
store i32 %0, i32* %4
store i32* %1, i32** %5
store i32* %2, i32** %6
%7 = load i32, i32* %4
%8 = icmp sge i32 %7, 1
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = load i32, i32* %4
%12 = icmp sle i32 %11, 32768
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = load i32, i32* %4
%16 = icmp sle i32 %15, 2
br i1 %16, label %17, label %22
17: ; preds = %3
%18 = load i32, i32* %4
%19 = sub nsw i32 %18, 1
%20 = load i32*, i32** %5
store i32 %19, i32* %20
%21 = load i32*, i32** %6
store i32 0, i32* %21
br label %27
22: ; preds = %3
%23 = load i32, i32* %4
%24 = load i32*, i32** %5
%25 = load i32*, i32** %6
%26 = call i32 @compute_dist_icf_code(i32 %23, i32* %24, i32* %25)
br label %27
27: ; preds = %22, %17
ret void
}

LLVM IR (-O2):
define void @get_dist_icf_code(i32 %0, i32* %1, i32* %2) {
%4 = icmp sgt i32 %0, 0
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = icmp slt i32 %0, 32769
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = icmp slt i32 %0, 3
br i1 %10, label %11, label %13
11: ; preds = %3
%12 = add nsw i32 %0, -1
store i32 %12, i32* %1
store i32 0, i32* %2
br label %15
13: ; preds = %3
%14 = tail call i32 @compute_dist_icf_code(i32 %0, i32* %1, i32* %2)
br label %15
15: ; preds = %13, %11
ret void
}