#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 STC3100_ReadByte(int);
int STC3100_WriteByte(int, int);
int STC3100_Startup(void) {
  int s32_res;
  s32_res = STC3100_ReadByte(0x18);
  if (s32_res != 0x10)
    return (-1);
  STC3100_ReadByte(0x01);
  s32_res = STC3100_WriteByte(0x01, 0x02);
  if (s32_res != 0)
    return (s32_res);
  s32_res = STC3100_WriteByte(0x00, 0x10);
  if (s32_res != 0)
    return (s32_res);
  return (0);
}


x86 assembly (clang, -O0):
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x18,%edi
call   1030 <STC3100_ReadByte@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x10,-0x8(%rbp)
je     114b <STC3100_Startup+0x2b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a7 <STC3100_Startup+0x87>
mov    $0x1,%edi
call   1030 <STC3100_ReadByte@plt>
mov    $0x1,%edi
mov    $0x2,%esi
call   1040 <STC3100_WriteByte@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     117c <STC3100_Startup+0x5c>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a7 <STC3100_Startup+0x87>
xor    %edi,%edi
mov    $0x10,%esi
call   1040 <STC3100_WriteByte@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11a0 <STC3100_Startup+0x80>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a7 <STC3100_Startup+0x87>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
push   %rax
mov    $0x18,%edi
call   1030 <STC3100_ReadByte@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    $0x10,%ecx
jne    1154 <STC3100_Startup+0x34>
mov    $0x1,%edi
call   1030 <STC3100_ReadByte@plt>
mov    $0x1,%edi
mov    $0x2,%esi
call   1040 <STC3100_WriteByte@plt>
test   %eax,%eax
je     1156 <STC3100_Startup+0x36>
pop    %rcx
ret
xor    %edi,%edi
mov    $0x10,%esi
pop    %rax
jmp    1040 <STC3100_WriteByte@plt>

LLVM IR (-O0):
define i32 @STC3100_Startup() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 @STC3100_ReadByte(i32 24)
store i32 %3, i32* %2
%4 = load i32, i32* %2
%5 = icmp ne i32 %4, 16
br i1 %5, label %6, label %7
6: ; preds = %0
store i32 -1, i32* %1
br label %21
7: ; preds = %0
%8 = call i32 @STC3100_ReadByte(i32 1)
%9 = call i32 @STC3100_WriteByte(i32 1, i32 2)
store i32 %9, i32* %2
%10 = load i32, i32* %2
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = load i32, i32* %2
store i32 %13, i32* %1
br label %21
14: ; preds = %7
%15 = call i32 @STC3100_WriteByte(i32 0, i32 16)
store i32 %15, i32* %2
%16 = load i32, i32* %2
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = load i32, i32* %2
store i32 %19, i32* %1
br label %21
20: ; preds = %14
store i32 0, i32* %1
br label %21
21: ; preds = %20, %18, %12, %6
%22 = load i32, i32* %1
ret i32 %22
}

LLVM IR (-O2):
define i32 @STC3100_Startup() {
%1 = tail call i32 @STC3100_ReadByte(i32 24)
%2 = icmp eq i32 %1, 16
br i1 %2, label %3, label %9
3: ; preds = %0
%4 = tail call i32 @STC3100_ReadByte(i32 1)
%5 = tail call i32 @STC3100_WriteByte(i32 1, i32 2)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 @STC3100_WriteByte(i32 0, i32 16)
br label %9
9: ; preds = %7, %3, %0
%10 = phi i32 [ -1, %0 ], [ %5, %3 ], [ %8, %7 ]
ret i32 %10
}