#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*/ port_out(unsigned int, int);
int /*<<< orphan*/ timing_uPause(int);
void stv5730_write16bit(unsigned int port, unsigned int flags,
                        unsigned int value) {
  int i;
  timing_uPause(400);
  port_out(port, 0x08 + flags);
  timing_uPause(400);
  port_out(port, 0x08 + 0x04 + flags);
  timing_uPause(400);
  port_out(port, 0x04 + flags);
  for (i = 15; i >= 0; i--) {
    char databit = ((value & (1 << i)) != 0) ? 0x10 : 0;
    port_out(port, databit + 0x04 + flags);
    timing_uPause(400);
    port_out(port, databit + flags);
    timing_uPause(400);
    port_out(port, databit + 0x04 + flags);
    timing_uPause(400);
  }
  timing_uPause(400);
  port_out(port, 0x08 + 0x04 + flags);
  timing_uPause(400);
  port_out(port, 0x08 + flags);
  timing_uPause(400);
}


x86 assembly (clang, -O0):
<stv5730_write16bit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    $0x190,%edi
call   1030 <timing_uPause@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
add    $0x8,%esi
call   1040 <port_out@plt>
mov    $0x190,%edi
call   1030 <timing_uPause@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
add    $0xc,%esi
call   1040 <port_out@plt>
mov    $0x190,%edi
call   1030 <timing_uPause@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
add    $0x4,%esi
call   1040 <port_out@plt>
movl   $0xf,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jl     1208 <stv5730_write16bit+0xe8>
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
and    %eax,%edx
xor    %eax,%eax
mov    $0x10,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,-0x11(%rbp)
mov    -0x4(%rbp),%edi
movsbl -0x11(%rbp),%esi
add    $0x4,%esi
add    -0x8(%rbp),%esi
call   1040 <port_out@plt>
mov    $0x190,%edi
call   1030 <timing_uPause@plt>
mov    -0x4(%rbp),%edi
movsbl -0x11(%rbp),%esi
add    -0x8(%rbp),%esi
call   1040 <port_out@plt>
mov    $0x190,%edi
call   1030 <timing_uPause@plt>
mov    -0x4(%rbp),%edi
movsbl -0x11(%rbp),%esi
add    $0x4,%esi
add    -0x8(%rbp),%esi
call   1040 <port_out@plt>
mov    $0x190,%edi
call   1030 <timing_uPause@plt>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    1180 <stv5730_write16bit+0x60>
mov    $0x190,%edi
call   1030 <timing_uPause@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
add    $0xc,%esi
call   1040 <port_out@plt>
mov    $0x190,%edi
call   1030 <timing_uPause@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
add    $0x8,%esi
call   1040 <port_out@plt>
mov    $0x190,%edi
call   1030 <timing_uPause@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stv5730_write16bit>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %esi,%r13d
mov    %edi,%ebx
mov    $0x190,%edi
call   1030 <timing_uPause@plt>
lea    0x8(%r13),%esi
mov    %ebx,%edi
mov    %esi,0x4(%rsp)
call   1040 <port_out@plt>
mov    $0x190,%edi
call   1030 <timing_uPause@plt>
lea    0xc(%r13),%esi
mov    %ebx,%edi
mov    %esi,(%rsp)
call   1040 <port_out@plt>
mov    $0x190,%edi
call   1030 <timing_uPause@plt>
lea    0x4(%r13),%esi
mov    %ebx,%edi
call   1040 <port_out@plt>
mov    $0xf,%r12d
nop
xor    %ebp,%ebp
bt     %r12d,%r15d
setb   %bpl
shl    $0x4,%ebp
lea    0x4(%rbp,%r13,1),%r14d
mov    %ebx,%edi
mov    %r14d,%esi
call   1040 <port_out@plt>
mov    $0x190,%edi
call   1030 <timing_uPause@plt>
add    %r13d,%ebp
mov    %ebx,%edi
mov    %ebp,%esi
call   1040 <port_out@plt>
mov    $0x190,%edi
call   1030 <timing_uPause@plt>
mov    %ebx,%edi
mov    %r14d,%esi
call   1040 <port_out@plt>
mov    $0x190,%edi
call   1030 <timing_uPause@plt>
add    $0xffffffff,%r12d
jb     1180 <stv5730_write16bit+0x60>
mov    $0x190,%edi
call   1030 <timing_uPause@plt>
mov    %ebx,%edi
mov    (%rsp),%esi
call   1040 <port_out@plt>
mov    $0x190,%edi
call   1030 <timing_uPause@plt>
mov    %ebx,%edi
mov    0x4(%rsp),%esi
call   1040 <port_out@plt>
mov    $0x190,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <timing_uPause@plt>

LLVM IR (-O0):
define void @stv5730_write16bit(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = call i32 @timing_uPause(i32 400)
%10 = load i32, i32* %4
%11 = load i32, i32* %5
%12 = add i32 8, %11
%13 = call i32 @port_out(i32 %10, i32 %12)
%14 = call i32 @timing_uPause(i32 400)
%15 = load i32, i32* %4
%16 = load i32, i32* %5
%17 = add i32 12, %16
%18 = call i32 @port_out(i32 %15, i32 %17)
%19 = call i32 @timing_uPause(i32 400)
%20 = load i32, i32* %4
%21 = load i32, i32* %5
%22 = add i32 4, %21
%23 = call i32 @port_out(i32 %20, i32 %22)
store i32 15, i32* %7
br label %24
24: ; preds = %59, %3
%25 = load i32, i32* %7
%26 = icmp sge i32 %25, 0
br i1 %26, label %27, label %62
27: ; preds = %24
%28 = load i32, i32* %6
%29 = load i32, i32* %7
%30 = shl i32 1, %29
%31 = and i32 %28, %30
%32 = icmp ne i32 %31, 0
%33 = zext i1 %32 to i64
%34 = select i1 %32, i32 16, i32 0
%35 = trunc i32 %34 to i8
store i8 %35, i8* %8
%36 = load i32, i32* %4
%37 = load i8, i8* %8
%38 = sext i8 %37 to i32
%39 = add nsw i32 %38, 4
%40 = load i32, i32* %5
%41 = add i32 %39, %40
%42 = call i32 @port_out(i32 %36, i32 %41)
%43 = call i32 @timing_uPause(i32 400)
%44 = load i32, i32* %4
%45 = load i8, i8* %8
%46 = sext i8 %45 to i32
%47 = load i32, i32* %5
%48 = add i32 %46, %47
%49 = call i32 @port_out(i32 %44, i32 %48)
%50 = call i32 @timing_uPause(i32 400)
%51 = load i32, i32* %4
%52 = load i8, i8* %8
%53 = sext i8 %52 to i32
%54 = add nsw i32 %53, 4
%55 = load i32, i32* %5
%56 = add i32 %54, %55
%57 = call i32 @port_out(i32 %51, i32 %56)
%58 = call i32 @timing_uPause(i32 400)
br label %59
59: ; preds = %27
%60 = load i32, i32* %7
%61 = add nsw i32 %60, -1
store i32 %61, i32* %7
br label %24
62: ; preds = %24
%63 = call i32 @timing_uPause(i32 400)
%64 = load i32, i32* %4
%65 = load i32, i32* %5
%66 = add i32 12, %65
%67 = call i32 @port_out(i32 %64, i32 %66)
%68 = call i32 @timing_uPause(i32 400)
%69 = load i32, i32* %4
%70 = load i32, i32* %5
%71 = add i32 8, %70
%72 = call i32 @port_out(i32 %69, i32 %71)
%73 = call i32 @timing_uPause(i32 400)
ret void
}

LLVM IR (-O2):
define void @stv5730_write16bit(i32 %0, i32 %1, i32 %2) {
%4 = tail call i32 @timing_uPause(i32 400)
%5 = add i32 %1, 8
%6 = tail call i32 @port_out(i32 %0, i32 %5)
%7 = tail call i32 @timing_uPause(i32 400)
%8 = add i32 %1, 12
%9 = tail call i32 @port_out(i32 %0, i32 %8)
%10 = tail call i32 @timing_uPause(i32 400)
%11 = add i32 %1, 4
%12 = tail call i32 @port_out(i32 %0, i32 %11)
br label %13
13: ; preds = %3, %13
%14 = phi i32 [ 15, %3 ], [ %28, %13 ]
%15 = shl nuw i32 1, %14
%16 = and i32 %15, %2
%17 = icmp eq i32 %16, 0
%18 = select i1 %17, i32 0, i32 16
%19 = or i32 %18, 4
%20 = add i32 %19, %1
%21 = tail call i32 @port_out(i32 %0, i32 %20)
%22 = tail call i32 @timing_uPause(i32 400)
%23 = add i32 %18, %1
%24 = tail call i32 @port_out(i32 %0, i32 %23)
%25 = tail call i32 @timing_uPause(i32 400)
%26 = tail call i32 @port_out(i32 %0, i32 %20)
%27 = tail call i32 @timing_uPause(i32 400)
%28 = add nsw i32 %14, -1
%29 = icmp eq i32 %14, 0
br i1 %29, label %30, label %13
30: ; preds = %13
%31 = tail call i32 @timing_uPause(i32 400)
%32 = tail call i32 @port_out(i32 %0, i32 %8)
%33 = tail call i32 @timing_uPause(i32 400)
%34 = tail call i32 @port_out(i32 %0, i32 %5)
%35 = tail call i32 @timing_uPause(i32 400)
ret void
}