#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 */

/* Variables and functions */
int /*<<< orphan*/ outb(unsigned short const, unsigned int);
scalar_t__ serial_is_transmit_empty(unsigned short const);
void serial_write_int(unsigned int i, const unsigned short com) {
  unsigned int k = 0;
  for (; k < 4; ++k) {
    while (serial_is_transmit_empty(com) == 0)
      ;
    outb(com, (i >> (3 - k)) & 0xFF);
  }
}


x86 assembly (clang, -O0):
<serial_write_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %si,%ax
mov    %edi,-0x4(%rbp)
mov    %ax,-0x6(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x4,-0xc(%rbp)
jae    118d <serial_write_int+0x6d>
jmp    1148 <serial_write_int+0x28>
movzwl -0x6(%rbp),%edi
call   1030 <serial_is_transmit_empty@plt>
cmp    $0x0,%rax
jne    1160 <serial_write_int+0x40>
jmp    1148 <serial_write_int+0x28>
mov    -0x6(%rbp),%ax
mov    -0x4(%rbp),%esi
mov    $0x3,%ecx
sub    -0xc(%rbp),%ecx
shr    %cl,%esi
and    $0xff,%esi
movzwl %ax,%edi
call   1040 <outb@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1139 <serial_write_int+0x19>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serial_write_int>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
movzwl %si,%ebp
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
call   1030 <serial_is_transmit_empty@plt>
test   %rax,%rax
je     1130 <serial_write_int+0x10>
mov    %ebx,%eax
shr    $0x3,%eax
movzbl %al,%esi
mov    %ebp,%edi
call   1040 <outb@plt>
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
call   1030 <serial_is_transmit_empty@plt>
test   %rax,%rax
je     1150 <serial_write_int+0x30>
mov    %ebx,%eax
shr    $0x2,%eax
movzbl %al,%esi
mov    %ebp,%edi
call   1040 <outb@plt>
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
call   1030 <serial_is_transmit_empty@plt>
test   %rax,%rax
je     1170 <serial_write_int+0x50>
mov    %ebx,%eax
shr    %eax
movzbl %al,%esi
mov    %ebp,%edi
call   1040 <outb@plt>
nopw   0x0(%rax,%rax,1)
mov    %ebp,%edi
call   1030 <serial_is_transmit_empty@plt>
test   %rax,%rax
je     1190 <serial_write_int+0x70>
movzbl %bl,%esi
mov    %ebp,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <outb@plt>

LLVM IR (-O0):
define void @serial_write_int(i32 %0, i16 zeroext %1) {
%3 = alloca i32
%4 = alloca i16
%5 = alloca i32
store i32 %0, i32* %3
store i16 %1, i16* %4
store i32 0, i32* %5
br label %6
6: ; preds = %23, %2
%7 = load i32, i32* %5
%8 = icmp ult i32 %7, 4
br i1 %8, label %9, label %26
9: ; preds = %6
br label %10
10: ; preds = %14, %9
%11 = load i16, i16* %4
%12 = call i64 @serial_is_transmit_empty(i16 zeroext %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %10
br label %10
15: ; preds = %10
%16 = load i16, i16* %4
%17 = load i32, i32* %3
%18 = load i32, i32* %5
%19 = sub i32 3, %18
%20 = lshr i32 %17, %19
%21 = and i32 %20, 255
%22 = call i32 @outb(i16 zeroext %16, i32 %21)
br label %23
23: ; preds = %15
%24 = load i32, i32* %5
%25 = add i32 %24, 1
store i32 %25, i32* %5
br label %6
26: ; preds = %6
ret void
}

LLVM IR (-O2):
define void @serial_write_int(i32 %0, i16 zeroext %1) {
br label %3
3: ; preds = %2, %3
%4 = tail call i64 @serial_is_transmit_empty(i16 zeroext %1)
%5 = icmp eq i64 %4, 0
br i1 %5, label %3, label %6
6: ; preds = %3
%7 = lshr i32 %0, 3
%8 = and i32 %7, 255
%9 = tail call i32 @outb(i16 zeroext %1, i32 %8)
br label %10
10: ; preds = %10, %6
%11 = tail call i64 @serial_is_transmit_empty(i16 zeroext %1)
%12 = icmp eq i64 %11, 0
br i1 %12, label %10, label %13
13: ; preds = %10
%14 = lshr i32 %0, 2
%15 = and i32 %14, 255
%16 = tail call i32 @outb(i16 zeroext %1, i32 %15)
br label %17
17: ; preds = %17, %13
%18 = tail call i64 @serial_is_transmit_empty(i16 zeroext %1)
%19 = icmp eq i64 %18, 0
br i1 %19, label %17, label %20
20: ; preds = %17
%21 = lshr i32 %0, 1
%22 = and i32 %21, 255
%23 = tail call i32 @outb(i16 zeroext %1, i32 %22)
br label %24
24: ; preds = %24, %20
%25 = tail call i64 @serial_is_transmit_empty(i16 zeroext %1)
%26 = icmp eq i64 %25, 0
br i1 %26, label %24, label %27
27: ; preds = %24
%28 = and i32 %0, 255
%29 = tail call i32 @outb(i16 zeroext %1, i32 %28)
ret void
}