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

/* Variables and functions */
int /*<<< orphan*/ printf(char *);
int read_byte_data(int, int);
uint8_t get_port(uint8_t address, uint8_t port, uint8_t a_register,
                 uint8_t b_register) {
  if (port == 0) {
    return (read_byte_data(address, a_register));
  } else if (port == 1) {
    return (read_byte_data(address, b_register));
  } else {
    printf("port out of range: 0 or 1");
    return (0);
  }
}


x86 assembly (clang, -O0):
<get_port>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1151 <get_port+0x31>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1030 <read_byte_data@plt>
mov    %eax,-0x4(%rbp)
jmp    1181 <get_port+0x61>
cmpl   $0x1,-0xc(%rbp)
jne    116e <get_port+0x4e>
mov    -0x8(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1030 <read_byte_data@plt>
mov    %eax,-0x4(%rbp)
jmp    1181 <get_port+0x61>
lea    0xe8b(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_port>:
cmp    $0x1,%esi
je     1130 <get_port+0x10>
test   %esi,%esi
jne    1137 <get_port+0x17>
mov    %edx,%esi
jmp    1030 <read_byte_data@plt>
mov    %ecx,%esi
jmp    1030 <read_byte_data@plt>
push   %rax
lea    0xec1(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [26 x i8] c"port out of range: 0 or 1\00"
define i32 @get_port(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%10 = load i32, i32* %7
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %4
%13 = load i32, i32* %6
%14 = load i32, i32* %8
%15 = call i32 @read_byte_data(i32 %13, i32 %14)
store i32 %15, i32* %5
br label %25
16: ; preds = %4
%17 = load i32, i32* %7
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %23
19: ; preds = %16
%20 = load i32, i32* %6
%21 = load i32, i32* %9
%22 = call i32 @read_byte_data(i32 %20, i32 %21)
store i32 %22, i32* %5
br label %25
23: ; preds = %16
%24 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %5
br label %25
25: ; preds = %23, %19, %12
%26 = load i32, i32* %5
ret i32 %26
}

LLVM IR (-O2):
@.str = [26 x i8] c"port out of range: 0 or 1\00"
define i32 @get_port(i32 %0, i32 %1, i32 %2, i32 %3) {
switch i32 %1, label %9 [
i32 0, label %5
i32 1, label %7
]
5: ; preds = %4
%6 = tail call i32 @read_byte_data(i32 %0, i32 %2)
br label %11
7: ; preds = %4
%8 = tail call i32 @read_byte_data(i32 %0, i32 %3)
br label %11
9: ; preds = %4
%10 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %7, %5
%12 = phi i32 [ %6, %5 ], [ %8, %7 ], [ 0, %9 ]
ret i32 %12
}