#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 */
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ clientCreate(char const *, unsigned int);
int /*<<< orphan*/ clientDisconnected();
int /*<<< orphan*/ clientFree();
scalar_t__ clientRead(char *);
scalar_t__ clientWrite(char *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
void clientStart(const char *host, unsigned int port) {
  assert(host != NULL);
  clientCreate(host, port);
  char buffer[4096];
  while (true) {
    printf("rtdoc> ");
    fgets(buffer, sizeof(buffer), stdin);
    if (clientWrite(buffer) < 0 || clientRead(buffer) < 0)
      clientDisconnected();
    printf("%s", buffer);
  }
  clientFree();
}


x86 assembly (clang, -O0):
<clientStart>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1010,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1070 <clientCreate@plt>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x1010(%rbp),%rdi
mov    0x2e2c(%rip),%rax
mov    (%rax),%edx
mov    $0x1000,%esi
call   1060 <fgets@plt>
lea    -0x1010(%rbp),%rdi
call   1090 <clientWrite@plt>
cmp    $0x0,%rax
jl     11f4 <clientStart+0x84>
lea    -0x1010(%rbp),%rdi
call   1050 <clientRead@plt>
cmp    $0x0,%rax
jge    11fb <clientStart+0x8b>
mov    $0x0,%al
call   1030 <clientDisconnected@plt>
lea    -0x1010(%rbp),%rsi
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11a0 <clientStart+0x30>

x86 assembly (clang, -O2):
<clientStart>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x1008,%rsp
mov    %esi,%ebp
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1080 <assert@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1070 <clientCreate@plt>
lea    0xe5f(%rip),%r14
mov    0x2e40(%rip),%rbp
mov    %rsp,%rbx
lea    0xe56(%rip),%r15
jmp    11d4 <clientStart+0x64>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1030 <clientDisconnected@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x0(%rbp),%edx
mov    %rbx,%rdi
mov    $0x1000,%esi
call   1060 <fgets@plt>
mov    %rbx,%rdi
call   1090 <clientWrite@plt>
test   %rax,%rax
js     11c0 <clientStart+0x50>
mov    %rbx,%rdi
call   1050 <clientRead@plt>
test   %rax,%rax
jns    11c7 <clientStart+0x57>
jmp    11c0 <clientStart+0x50>

LLVM IR (-O0):
@.str = [8 x i8] c"rtdoc> \00"
@stdin = global i32 0
@.str.1 = [3 x i8] c"%s\00"
define void @clientStart(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [4096 x i8]
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = load i8*, i8** %3
%11 = load i32, i32* %4
%12 = call i32 @clientCreate(i8* %10, i32 %11)
br label %13
13: ; preds = %2, %27
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%15 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%16 = load i32, i32* @stdin
%17 = call i32 @fgets(i8* %15, i32 4096, i32 %16)
%18 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%19 = call i64 @clientWrite(i8* %18)
%20 = icmp slt i64 %19, 0
br i1 %20, label %25, label %21
21: ; preds = %13
%22 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%23 = call i64 @clientRead(i8* %22)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %21, %13
%26 = call i32 (...) @clientDisconnected()
br label %27
27: ; preds = %25, %21
%28 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %28)
br label %13
}

LLVM IR (-O2):
@.str = [8 x i8] c"rtdoc> \00"
@stdin = global i32 0
@.str.1 = [3 x i8] c"%s\00"
define void @clientStart(i8* %0, i32 %1) {
%3 = alloca [4096 x i8]
%4 = icmp ne i8* %0, null
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = tail call i32 @clientCreate(i8* %0, i32 %1)
%8 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
br label %9
9: ; preds = %20, %2
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @stdin
%12 = call i32 @fgets(i8* %8, i32 4096, i32 %11)
%13 = call i64 @clientWrite(i8* %8)
%14 = icmp slt i64 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %9
%16 = call i64 @clientRead(i8* %8)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %15, %9
%19 = call i32 (...) @clientDisconnected()
br label %20
20: ; preds = %18, %15
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %8)
br label %9
}