#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 /*<<< orphan*/ write_byte_data(int, int, int);
void set_port(uint8_t port, uint8_t value, uint8_t a_register,
              uint8_t b_register) {
  if (port == 0) {
    write_byte_data(0x20, a_register, value);
  } else if (port == 1) {
    write_byte_data(0x20, b_register, value);
  } else {
    printf("port out of range: 0 or 1");
  }
}


x86 assembly (clang, -O0):
<set_port>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    1153 <set_port+0x33>
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    $0x20,%edi
call   1040 <write_byte_data@plt>
jmp    1183 <set_port+0x63>
cmpl   $0x1,-0x4(%rbp)
jne    1172 <set_port+0x52>
mov    -0x10(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    $0x20,%edi
call   1040 <write_byte_data@plt>
jmp    117e <set_port+0x5e>
lea    0xe87(%rip),%rdi
call   1030 <printf@plt>
jmp    1183 <set_port+0x63>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_port>:
mov    %esi,%eax
cmp    $0x1,%edi
je     1139 <set_port+0x19>
test   %edi,%edi
jne    1147 <set_port+0x27>
mov    $0x20,%edi
mov    %edx,%esi
mov    %eax,%edx
jmp    1040 <write_byte_data@plt>
mov    $0x20,%edi
mov    %ecx,%esi
mov    %eax,%edx
jmp    1040 <write_byte_data@plt>
lea    0xeb2(%rip),%rdi
jmp    1030 <printf@plt>

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

LLVM IR (-O2):
@.str = [26 x i8] c"port out of range: 0 or 1\00"
define void @set_port(i32 %0, i32 %1, i32 %2, i32 %3) {
switch i32 %0, label %9 [
i32 0, label %5
i32 1, label %7
]
5: ; preds = %4
%6 = tail call i32 @write_byte_data(i32 32, i32 %2, i32 %1)
br label %11
7: ; preds = %4
%8 = tail call i32 @write_byte_data(i32 32, i32 %3, i32 %1)
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 = %7, %9, %5
ret void
}