#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 */
char ReadPacket(int /*<<< orphan*/, char **, int);
int /*<<< orphan*/ WritePacket(int, char, char *);
int /*<<< orphan*/ free(char *);
int main() {
  int eof_permitted = 0;
  for (;;) {
    char type;
    char *message;
    type = ReadPacket(0, &message, eof_permitted);
    if (type == 0) {
      return 0;
    }
    WritePacket(1, type, message);
    free(message);
    eof_permitted = !eof_permitted;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%edx
xor    %edi,%edi
lea    -0x18(%rbp),%rsi
call   1040 <ReadPacket@plt>
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%eax
cmp    $0x0,%eax
jne    116c <main+0x3c>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret
mov    -0x9(%rbp),%al
mov    -0x18(%rbp),%rdx
mov    $0x1,%edi
movsbl %al,%esi
call   1050 <WritePacket@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x8(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x8(%rbp)
jmp    1146 <main+0x16>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsp,%rsi
xor    %ebx,%ebx
xor    %edi,%edi
xor    %edx,%edx
call   1040 <ReadPacket@plt>
test   %al,%al
je     117d <main+0x4d>
mov    %rsp,%r14
nopl   0x0(%rax)
mov    (%rsp),%rdx
movsbl %al,%esi
mov    $0x1,%edi
call   1050 <WritePacket@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
xor    $0x1,%ebx
xor    %edi,%edi
mov    %r14,%rsi
mov    %ebx,%edx
call   1040 <ReadPacket@plt>
test   %al,%al
jne    1150 <main+0x20>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8
%4 = alloca i8*
store i32 0, i32* %1
store i32 0, i32* %2
br label %5
5: ; preds = %12, %0
%6 = load i32, i32* %2
%7 = call signext i8 @ReadPacket(i32 0, i8** %4, i32 %6)
store i8 %7, i8* %3
%8 = load i8, i8* %3
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %5
ret i32 0
12: ; preds = %5
%13 = load i8, i8* %3
%14 = load i8*, i8** %4
%15 = call i32 @WritePacket(i32 1, i8 signext %13, i8* %14)
%16 = load i8*, i8** %4
%17 = call i32 @free(i8* %16)
%18 = load i32, i32* %2
%19 = icmp ne i32 %18, 0
%20 = xor i1 %19, true
%21 = zext i1 %20 to i32
store i32 %21, i32* %2
br label %5
}

LLVM IR (-O2):
define i32 @main() {
%1 = alloca i8*
%2 = bitcast i8** %1 to i8*
%3 = call signext i8 @ReadPacket(i32 0, i8** %1, i32 0)
%4 = icmp eq i8 %3, 0
br i1 %4, label %15, label %5
5: ; preds = %0, %5
%6 = phi i8 [ %13, %5 ], [ %3, %0 ]
%7 = phi i32 [ %12, %5 ], [ 0, %0 ]
%8 = load i8*, i8** %1
%9 = call i32 @WritePacket(i32 1, i8 signext %6, i8* %8)
%10 = load i8*, i8** %1
%11 = call i32 @free(i8* %10)
%12 = xor i32 %7, 1
%13 = call signext i8 @ReadPacket(i32 0, i8** %1, i32 %12)
%14 = icmp eq i8 %13, 0
br i1 %14, label %15, label %5
15: ; preds = %5, %0
ret i32 0
}