#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*/ printf(char *, unsigned int, unsigned int, unsigned int);
int receiveByte(int);
int /*<<< orphan*/ sendByte(int, unsigned char);
int /*<<< orphan*/ updateCarry(unsigned char, unsigned int *);
void tube_Byte(unsigned int *reg) {
  if (0) {
    printf("%08x %08x %08x\r\n", reg[0], reg[1], reg[2]);
  }
  unsigned char cy;
  unsigned char a = reg[0] & 0xff;
  unsigned char x = reg[1] & 0xff;
  unsigned char y = reg[2] & 0xff;
  if (a < 128) {
    sendByte(2, 0x04);
    sendByte(2, x);
    sendByte(2, a);
    x = receiveByte(2);
    reg[1] = x;
  } else {
    sendByte(2, 0x06);
    sendByte(2, x);
    sendByte(2, y);
    sendByte(2, a);
    cy = receiveByte(2) & 0x80;
    y = receiveByte(2);
    x = receiveByte(2);
    reg[1] = x;
    reg[2] = y;
    updateCarry(cy, reg);
  }
  if (0) {
    printf("%08x %08x %08x\r\n", reg[0], reg[1], reg[2]);
  }
}


x86 assembly (clang, -O0):
<tube_Byte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
and    $0xff,%eax
mov    %al,-0xa(%rbp)
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%eax
and    $0xff,%eax
mov    %al,-0xb(%rbp)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%eax
and    $0xff,%eax
mov    %al,-0xc(%rbp)
movzbl -0xa(%rbp),%eax
cmp    $0x80,%eax
jge    11bf <tube_Byte+0x8f>
mov    $0x2,%edi
mov    $0x4,%esi
call   1050 <sendByte@plt>
mov    $0x2,%edi
movzbl -0xb(%rbp),%esi
call   1050 <sendByte@plt>
mov    $0x2,%edi
movzbl -0xa(%rbp),%esi
call   1050 <sendByte@plt>
mov    $0x2,%edi
call   1030 <receiveByte@plt>
mov    %al,-0xb(%rbp)
movzbl -0xb(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x4(%rax)
jmp    1249 <tube_Byte+0x119>
mov    $0x2,%edi
mov    $0x6,%esi
call   1050 <sendByte@plt>
mov    $0x2,%edi
movzbl -0xb(%rbp),%esi
call   1050 <sendByte@plt>
mov    $0x2,%edi
movzbl -0xc(%rbp),%esi
call   1050 <sendByte@plt>
mov    $0x2,%edi
movzbl -0xa(%rbp),%esi
call   1050 <sendByte@plt>
mov    $0x2,%edi
call   1030 <receiveByte@plt>
and    $0x80,%eax
mov    %al,-0x9(%rbp)
mov    $0x2,%edi
call   1030 <receiveByte@plt>
mov    %al,-0xc(%rbp)
mov    $0x2,%edi
call   1030 <receiveByte@plt>
mov    %al,-0xb(%rbp)
movzbl -0xb(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x4(%rax)
movzbl -0xc(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x9(%rbp),%al
mov    -0x8(%rbp),%rsi
movzbl %al,%edi
call   1040 <updateCarry@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tube_Byte>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    (%rdi),%ebp
mov    0x4(%rdi),%r15b
test   $0x80,%bpl
jne    118c <tube_Byte+0x5c>
mov    $0x2,%edi
mov    $0x4,%esi
call   1050 <sendByte@plt>
movzbl %r15b,%esi
mov    $0x2,%edi
call   1050 <sendByte@plt>
movzbl %bpl,%esi
mov    $0x2,%edi
call   1050 <sendByte@plt>
mov    $0x2,%edi
call   1030 <receiveByte@plt>
movzbl %al,%eax
mov    %eax,0x4(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
movzbl 0x8(%rbx),%r14d
mov    $0x2,%edi
mov    $0x6,%esi
call   1050 <sendByte@plt>
movzbl %r15b,%esi
mov    $0x2,%edi
call   1050 <sendByte@plt>
mov    $0x2,%edi
mov    %r14d,%esi
call   1050 <sendByte@plt>
movzbl %bpl,%esi
mov    $0x2,%edi
call   1050 <sendByte@plt>
mov    $0x2,%edi
call   1030 <receiveByte@plt>
mov    %eax,%ebp
mov    $0x2,%edi
call   1030 <receiveByte@plt>
mov    %eax,%r14d
mov    $0x2,%edi
call   1030 <receiveByte@plt>
movzbl %al,%eax
mov    %eax,0x4(%rbx)
movzbl %r14b,%eax
mov    %eax,0x8(%rbx)
and    $0x80,%ebp
mov    %ebp,%edi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <updateCarry@plt>

LLVM IR (-O0):
define void @tube_Byte(i32* %0) {
%2 = alloca i32*
%3 = alloca i8
%4 = alloca i8
%5 = alloca i8
%6 = alloca i8
store i32* %0, i32** %2
%7 = load i32*, i32** %2
%8 = getelementptr inbounds i32, i32* %7, i64 0
%9 = load i32, i32* %8
%10 = and i32 %9, 255
%11 = trunc i32 %10 to i8
store i8 %11, i8* %4
%12 = load i32*, i32** %2
%13 = getelementptr inbounds i32, i32* %12, i64 1
%14 = load i32, i32* %13
%15 = and i32 %14, 255
%16 = trunc i32 %15 to i8
store i8 %16, i8* %5
%17 = load i32*, i32** %2
%18 = getelementptr inbounds i32, i32* %17, i64 2
%19 = load i32, i32* %18
%20 = and i32 %19, 255
%21 = trunc i32 %20 to i8
store i8 %21, i8* %6
%22 = load i8, i8* %4
%23 = zext i8 %22 to i32
%24 = icmp slt i32 %23, 128
br i1 %24, label %25, label %37
25: ; preds = %1
%26 = call i32 @sendByte(i32 2, i8 zeroext 4)
%27 = load i8, i8* %5
%28 = call i32 @sendByte(i32 2, i8 zeroext %27)
%29 = load i8, i8* %4
%30 = call i32 @sendByte(i32 2, i8 zeroext %29)
%31 = call i32 @receiveByte(i32 2)
%32 = trunc i32 %31 to i8
store i8 %32, i8* %5
%33 = load i8, i8* %5
%34 = zext i8 %33 to i32
%35 = load i32*, i32** %2
%36 = getelementptr inbounds i32, i32* %35, i64 1
store i32 %34, i32* %36
br label %63
37: ; preds = %1
%38 = call i32 @sendByte(i32 2, i8 zeroext 6)
%39 = load i8, i8* %5
%40 = call i32 @sendByte(i32 2, i8 zeroext %39)
%41 = load i8, i8* %6
%42 = call i32 @sendByte(i32 2, i8 zeroext %41)
%43 = load i8, i8* %4
%44 = call i32 @sendByte(i32 2, i8 zeroext %43)
%45 = call i32 @receiveByte(i32 2)
%46 = and i32 %45, 128
%47 = trunc i32 %46 to i8
store i8 %47, i8* %3
%48 = call i32 @receiveByte(i32 2)
%49 = trunc i32 %48 to i8
store i8 %49, i8* %6
%50 = call i32 @receiveByte(i32 2)
%51 = trunc i32 %50 to i8
store i8 %51, i8* %5
%52 = load i8, i8* %5
%53 = zext i8 %52 to i32
%54 = load i32*, i32** %2
%55 = getelementptr inbounds i32, i32* %54, i64 1
store i32 %53, i32* %55
%56 = load i8, i8* %6
%57 = zext i8 %56 to i32
%58 = load i32*, i32** %2
%59 = getelementptr inbounds i32, i32* %58, i64 2
store i32 %57, i32* %59
%60 = load i8, i8* %3
%61 = load i32*, i32** %2
%62 = call i32 @updateCarry(i8 zeroext %60, i32* %61)
br label %63
63: ; preds = %37, %25
ret void
}

LLVM IR (-O2):
define void @tube_Byte(i32* %0) {
%2 = load i32, i32* %0
%3 = trunc i32 %2 to i8
%4 = getelementptr inbounds i32, i32* %0, i64 1
%5 = load i32, i32* %4
%6 = trunc i32 %5 to i8
%7 = getelementptr inbounds i32, i32* %0, i64 2
%8 = and i32 %2, 128
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %16
10: ; preds = %1
%11 = tail call i32 @sendByte(i32 2, i8 zeroext 4)
%12 = tail call i32 @sendByte(i32 2, i8 zeroext %6)
%13 = tail call i32 @sendByte(i32 2, i8 zeroext %3)
%14 = tail call i32 @receiveByte(i32 2)
%15 = and i32 %14, 255
store i32 %15, i32* %4
br label %31
16: ; preds = %1
%17 = load i32, i32* %7
%18 = trunc i32 %17 to i8
%19 = tail call i32 @sendByte(i32 2, i8 zeroext 6)
%20 = tail call i32 @sendByte(i32 2, i8 zeroext %6)
%21 = tail call i32 @sendByte(i32 2, i8 zeroext %18)
%22 = tail call i32 @sendByte(i32 2, i8 zeroext %3)
%23 = tail call i32 @receiveByte(i32 2)
%24 = trunc i32 %23 to i8
%25 = and i8 %24, -128
%26 = tail call i32 @receiveByte(i32 2)
%27 = tail call i32 @receiveByte(i32 2)
%28 = and i32 %27, 255
store i32 %28, i32* %4
%29 = and i32 %26, 255
store i32 %29, i32* %7
%30 = tail call i32 @updateCarry(i8 zeroext %25, i32* %0)
br label %31
31: ; preds = %16, %10
ret void
}