#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 unsigned int uint8_t;
typedef unsigned int uint32_t;

/* Variables and functions */
unsigned int GET_BE16(unsigned int const *);
unsigned int GET_BE32(unsigned int const *);
uint32_t hdlc_read_option(const uint8_t *buf, uint8_t size) {
  uint32_t option = 0U;
  if (size == 1U) {
    option = buf[0];
  } else if (size == 2U) {
    option = GET_BE16(&buf[0]);
  } else if (size == 4U) {
    option = GET_BE32(&buf[0]);
  } else {
    option = 0U;
  }
  return option;
}


x86 assembly (clang, -O0):
<hdlc_read_option>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    114e <hdlc_read_option+0x2e>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
jmp    1195 <hdlc_read_option+0x75>
cmpl   $0x2,-0xc(%rbp)
jne    1169 <hdlc_read_option+0x49>
mov    -0x8(%rbp),%rdi
call   1040 <GET_BE16@plt>
mov    %eax,-0x10(%rbp)
jmp    1190 <hdlc_read_option+0x70>
cmpl   $0x4,-0xc(%rbp)
jne    1184 <hdlc_read_option+0x64>
mov    -0x8(%rbp),%rdi
call   1030 <GET_BE32@plt>
mov    %eax,-0x10(%rbp)
jmp    118b <hdlc_read_option+0x6b>
movl   $0x0,-0x10(%rbp)
jmp    1190 <hdlc_read_option+0x70>
jmp    1195 <hdlc_read_option+0x75>
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hdlc_read_option>:
cmp    $0x4,%esi
je     1134 <hdlc_read_option+0x14>
cmp    $0x2,%esi
je     1139 <hdlc_read_option+0x19>
xor    %eax,%eax
cmp    $0x1,%esi
jne    1133 <hdlc_read_option+0x13>
mov    (%rdi),%eax
ret
jmp    1030 <GET_BE32@plt>
jmp    1040 <GET_BE16@plt>

LLVM IR (-O0):
define i32 @hdlc_read_option(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32 0, i32* %5
%6 = load i32, i32* %4
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load i32*, i32** %3
%10 = getelementptr inbounds i32, i32* %9, i64 0
%11 = load i32, i32* %10
store i32 %11, i32* %5
br label %29
12: ; preds = %2
%13 = load i32, i32* %4
%14 = icmp eq i32 %13, 2
br i1 %14, label %15, label %19
15: ; preds = %12
%16 = load i32*, i32** %3
%17 = getelementptr inbounds i32, i32* %16, i64 0
%18 = call i32 @GET_BE16(i32* %17)
store i32 %18, i32* %5
br label %28
19: ; preds = %12
%20 = load i32, i32* %4
%21 = icmp eq i32 %20, 4
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = load i32*, i32** %3
%24 = getelementptr inbounds i32, i32* %23, i64 0
%25 = call i32 @GET_BE32(i32* %24)
store i32 %25, i32* %5
br label %27
26: ; preds = %19
store i32 0, i32* %5
br label %27
27: ; preds = %26, %22
br label %28
28: ; preds = %27, %15
br label %29
29: ; preds = %28, %8
%30 = load i32, i32* %5
ret i32 %30
}

LLVM IR (-O2):
define i32 @hdlc_read_option(i32* %0, i32 %1) {
switch i32 %1, label %9 [
i32 1, label %3
i32 2, label %5
i32 4, label %7
]
3: ; preds = %2
%4 = load i32, i32* %0
br label %9
5: ; preds = %2
%6 = tail call i32 @GET_BE16(i32* %0)
br label %9
7: ; preds = %2
%8 = tail call i32 @GET_BE32(i32* %0)
br label %9
9: ; preds = %2, %5, %7, %3
%10 = phi i32 [ %4, %3 ], [ %6, %5 ], [ %8, %7 ], [ 0, %2 ]
ret i32 %10
}