#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 int receiveByte(int);
int /*<<< orphan*/ sendByte(int, unsigned int);
int /*<<< orphan*/ sendString(int, int, char *);
void tube_Find(unsigned int *reg) {
  sendByte(2, 0x12);
  sendByte(2, reg[0]);
  if (reg[0] == 0) {
    sendByte(2, reg[1]);
    receiveByte(2);
  } else {
    sendString(2, 0x0D, (char *)reg[1]);
    reg[0] = receiveByte(2);
  }
}


x86 assembly (clang, -O0):
<tube_Find>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x2,%edi
mov    $0x12,%esi
call   1050 <sendByte@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
mov    $0x2,%edi
call   1050 <sendByte@plt>
mov    -0x8(%rbp),%rax
cmpl   $0x0,(%rax)
jne    1188 <tube_Find+0x58>
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%esi
mov    $0x2,%edi
call   1050 <sendByte@plt>
mov    $0x2,%edi
call   1040 <receiveByte@plt>
jmp    11b2 <tube_Find+0x82>
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,%edx
mov    $0x2,%edi
mov    $0xd,%esi
call   1030 <sendString@plt>
mov    $0x2,%edi
call   1040 <receiveByte@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tube_Find>:
push   %rbx
mov    %rdi,%rbx
mov    $0x2,%edi
mov    $0x12,%esi
call   1050 <sendByte@plt>
mov    (%rbx),%esi
mov    $0x2,%edi
call   1050 <sendByte@plt>
cmpl   $0x0,(%rbx)
mov    0x4(%rbx),%edx
mov    $0x2,%edi
je     1174 <tube_Find+0x44>
mov    $0xd,%esi
call   1030 <sendString@plt>
mov    $0x2,%edi
call   1040 <receiveByte@plt>
mov    %eax,(%rbx)
pop    %rbx
ret
mov    %edx,%esi
call   1050 <sendByte@plt>
mov    $0x2,%edi
pop    %rbx
jmp    1040 <receiveByte@plt>

LLVM IR (-O0):
define void @tube_Find(i32* %0) {
%2 = alloca i32*
store i32* %0, i32** %2
%3 = call i32 @sendByte(i32 2, i32 18)
%4 = load i32*, i32** %2
%5 = getelementptr inbounds i32, i32* %4, i64 0
%6 = load i32, i32* %5
%7 = call i32 @sendByte(i32 2, i32 %6)
%8 = load i32*, i32** %2
%9 = getelementptr inbounds i32, i32* %8, i64 0
%10 = load i32, i32* %9
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %1
%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 @receiveByte(i32 2)
br label %28
18: ; preds = %1
%19 = load i32*, i32** %2
%20 = getelementptr inbounds i32, i32* %19, i64 1
%21 = load i32, i32* %20
%22 = zext i32 %21 to i64
%23 = inttoptr i64 %22 to i8*
%24 = call i32 @sendString(i32 2, i32 13, i8* %23)
%25 = call i32 @receiveByte(i32 2)
%26 = load i32*, i32** %2
%27 = getelementptr inbounds i32, i32* %26, i64 0
store i32 %25, i32* %27
br label %28
28: ; preds = %18, %12
ret void
}

LLVM IR (-O2):
define void @tube_Find(i32* nocapture %0) {
%2 = tail call i32 @sendByte(i32 2, i32 18)
%3 = load i32, i32* %0
%4 = tail call i32 @sendByte(i32 2, i32 %3)
%5 = load i32, i32* %0
%6 = icmp eq i32 %5, 0
%7 = getelementptr inbounds i32, i32* %0, i64 1
%8 = load i32, i32* %7
br i1 %6, label %9, label %12
9: ; preds = %1
%10 = tail call i32 @sendByte(i32 2, i32 %8)
%11 = tail call i32 @receiveByte(i32 2)
br label %17
12: ; preds = %1
%13 = zext i32 %8 to i64
%14 = inttoptr i64 %13 to i8*
%15 = tail call i32 @sendString(i32 2, i32 13, i8* %14)
%16 = tail call i32 @receiveByte(i32 2)
store i32 %16, i32* %0
br label %17
17: ; preds = %12, %9
ret void
}