#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 */
unsigned char receiveByte(int);
unsigned int receiveString(int, char, char *);
int /*<<< orphan*/ sendByte(int, int);
int /*<<< orphan*/ updateCarry(unsigned char, unsigned int *);
void tube_ReadLine(unsigned int *reg) {
  unsigned char resp;
  sendByte(2, 0x0A);
  sendByte(2, reg[3]);
  sendByte(2, reg[2]);
  sendByte(2, reg[1]);
  sendByte(2, 0x07);
  sendByte(2, 0x00);
  resp = receiveByte(2);
  updateCarry(resp & 0x80, reg);
  if ((resp & 0x80) == 0x00) {
    reg[1] = receiveString(2, '\r', (char *)reg[0]);
  }
}


x86 assembly (clang, -O0):
<tube_ReadLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x2,%edi
mov    $0xa,%esi
call   1060 <sendByte@plt>
mov    -0x8(%rbp),%rax
mov    0xc(%rax),%esi
mov    $0x2,%edi
call   1060 <sendByte@plt>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%esi
mov    $0x2,%edi
call   1060 <sendByte@plt>
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%esi
mov    $0x2,%edi
call   1060 <sendByte@plt>
mov    $0x2,%edi
mov    $0x7,%esi
call   1060 <sendByte@plt>
mov    $0x2,%edi
xor    %esi,%esi
call   1060 <sendByte@plt>
mov    $0x2,%edi
call   1030 <receiveByte@plt>
mov    %al,-0x9(%rbp)
movzbl -0x9(%rbp),%eax
and    $0x80,%eax
mov    -0x8(%rbp),%rsi
movzbl %al,%edi
call   1050 <updateCarry@plt>
movzbl -0x9(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
jne    11fd <tube_ReadLine+0xbd>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,%edx
mov    $0x2,%edi
mov    $0xd,%esi
call   1040 <receiveString@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x4(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tube_ReadLine>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x2,%edi
mov    $0xa,%esi
call   1060 <sendByte@plt>
mov    0xc(%rbx),%esi
mov    $0x2,%edi
call   1060 <sendByte@plt>
mov    0x8(%rbx),%esi
mov    $0x2,%edi
call   1060 <sendByte@plt>
mov    0x4(%rbx),%esi
mov    $0x2,%edi
call   1060 <sendByte@plt>
mov    $0x2,%edi
mov    $0x7,%esi
call   1060 <sendByte@plt>
mov    $0x2,%edi
xor    %esi,%esi
call   1060 <sendByte@plt>
mov    $0x2,%edi
call   1030 <receiveByte@plt>
and    $0x80,%al
movzbl %al,%ebp
mov    %ebp,%edi
mov    %rbx,%rsi
call   1050 <updateCarry@plt>
test   %bpl,%bpl
jne    11c9 <tube_ReadLine+0x89>
mov    (%rbx),%edx
mov    $0x2,%edi
mov    $0xd,%esi
call   1040 <receiveString@plt>
mov    %eax,0x4(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define void @tube_ReadLine(i32* %0) {
%2 = alloca i32*
%3 = alloca i8
store i32* %0, i32** %2
%4 = call i32 @sendByte(i32 2, i32 10)
%5 = load i32*, i32** %2
%6 = getelementptr inbounds i32, i32* %5, i64 3
%7 = load i32, i32* %6
%8 = call i32 @sendByte(i32 2, i32 %7)
%9 = load i32*, i32** %2
%10 = getelementptr inbounds i32, i32* %9, i64 2
%11 = load i32, i32* %10
%12 = call i32 @sendByte(i32 2, i32 %11)
%13 = load i32*, i32** %2
%14 = getelementptr inbounds i32, i32* %13, i64 1
%15 = load i32, i32* %14
%16 = call i32 @sendByte(i32 2, i32 %15)
%17 = call i32 @sendByte(i32 2, i32 7)
%18 = call i32 @sendByte(i32 2, i32 0)
%19 = call zeroext i8 @receiveByte(i32 2)
store i8 %19, i8* %3
%20 = load i8, i8* %3
%21 = zext i8 %20 to i32
%22 = and i32 %21, 128
%23 = trunc i32 %22 to i8
%24 = load i32*, i32** %2
%25 = call i32 @updateCarry(i8 zeroext %23, i32* %24)
%26 = load i8, i8* %3
%27 = zext i8 %26 to i32
%28 = and i32 %27, 128
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %39
30: ; preds = %1
%31 = load i32*, i32** %2
%32 = getelementptr inbounds i32, i32* %31, i64 0
%33 = load i32, i32* %32
%34 = zext i32 %33 to i64
%35 = inttoptr i64 %34 to i8*
%36 = call i32 @receiveString(i32 2, i8 signext 13, i8* %35)
%37 = load i32*, i32** %2
%38 = getelementptr inbounds i32, i32* %37, i64 1
store i32 %36, i32* %38
br label %39
39: ; preds = %30, %1
ret void
}

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