#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 */
struct frec {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ free_frec(struct frec *);
struct frec *lookup_frec(unsigned short, unsigned int);
unsigned short rand16();
unsigned short get_id(int force, unsigned short force_id, unsigned int crc) {
  unsigned short ret = 0;
  if (force) {
    struct frec *f = lookup_frec(force_id, crc);
    if (f)
      free_frec(f);
    ret = force_id;
  } else
    do
      ret = rand16();
    while (lookup_frec(ret, crc));
  return ret;
}


x86 assembly (clang, -O0):
<get_id>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %si,%ax
mov    %edi,-0x4(%rbp)
mov    %ax,-0x6(%rbp)
mov    %edx,-0xc(%rbp)
movw   $0x0,-0xe(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     1189 <get_id+0x59>
mov    -0x6(%rbp),%ax
mov    -0xc(%rbp),%esi
movzwl %ax,%edi
call   1050 <lookup_frec@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     117c <get_id+0x4c>
mov    -0x18(%rbp),%rdi
call   1030 <free_frec@plt>
mov    -0x6(%rbp),%ax
mov    %ax,-0xe(%rbp)
jmp    11b7 <get_id+0x87>
jmp    118e <get_id+0x5e>
mov    $0x0,%al
call   1040 <rand16@plt>
mov    %ax,-0xe(%rbp)
mov    -0xe(%rbp),%ax
mov    -0xc(%rbp),%esi
movzwl %ax,%edi
call   1050 <lookup_frec@plt>
cmp    $0x0,%rax
jne    118e <get_id+0x5e>
jmp    11b7 <get_id+0x87>
movzwl -0xe(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_id>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ebp
test   %edi,%edi
je     1160 <get_id+0x30>
mov    %esi,%ebx
movzwl %bx,%edi
mov    %ebp,%esi
call   1050 <lookup_frec@plt>
test   %rax,%rax
je     1178 <get_id+0x48>
mov    %rax,%rdi
call   1030 <free_frec@plt>
jmp    1178 <get_id+0x48>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1040 <rand16@plt>
mov    %eax,%ebx
movzwl %ax,%edi
mov    %ebp,%esi
call   1050 <lookup_frec@plt>
test   %rax,%rax
jne    1160 <get_id+0x30>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.frec = type { i32 }
define zeroext i16 @get_id(i32 %0, i16 zeroext %1, i32 %2) {
%4 = alloca i32
%5 = alloca i16
%6 = alloca i32
%7 = alloca i16
%8 = alloca %struct.frec*
store i32 %0, i32* %4
store i16 %1, i16* %5
store i32 %2, i32* %6
store i16 0, i16* %7
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %22
11: ; preds = %3
%12 = load i16, i16* %5
%13 = load i32, i32* %6
%14 = call %struct.frec* @lookup_frec(i16 zeroext %12, i32 %13)
store %struct.frec* %14, %struct.frec** %8
%15 = load %struct.frec*, %struct.frec** %8
%16 = icmp ne %struct.frec* %15, null
br i1 %16, label %17, label %20
17: ; preds = %11
%18 = load %struct.frec*, %struct.frec** %8
%19 = call i32 @free_frec(%struct.frec* %18)
br label %20
20: ; preds = %17, %11
%21 = load i16, i16* %5
store i16 %21, i16* %7
br label %31
22: ; preds = %3
br label %23
23: ; preds = %25, %22
%24 = call zeroext i16 (...) @rand16()
store i16 %24, i16* %7
br label %25
25: ; preds = %23
%26 = load i16, i16* %7
%27 = load i32, i32* %6
%28 = call %struct.frec* @lookup_frec(i16 zeroext %26, i32 %27)
%29 = icmp ne %struct.frec* %28, null
br i1 %29, label %23, label %30
30: ; preds = %25
br label %31
31: ; preds = %30, %20
%32 = load i16, i16* %7
ret i16 %32
}

LLVM IR (-O2):
%struct.frec = type { i32 }
define zeroext i16 @get_id(i32 %0, i16 zeroext %1, i32 %2) {
%4 = icmp eq i32 %0, 0
br i1 %4, label %10, label %5
5: ; preds = %3
%6 = tail call %struct.frec* @lookup_frec(i16 zeroext %1, i32 %2)
%7 = icmp eq %struct.frec* %6, null
br i1 %7, label %14, label %8
8: ; preds = %5
%9 = tail call i32 @free_frec(%struct.frec* %6)
br label %14
10: ; preds = %3, %10
%11 = tail call zeroext i16 (...) @rand16()
%12 = tail call %struct.frec* @lookup_frec(i16 zeroext %11, i32 %2)
%13 = icmp eq %struct.frec* %12, null
br i1 %13, label %14, label %10
14: ; preds = %10, %5, %8
%15 = phi i16 [ %1, %8 ], [ %1, %5 ], [ %11, %10 ]
ret i16 %15
}