#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*/ cerr(char *);
int /*<<< orphan*/ cflush();
int cgetw();
int /*<<< orphan*/ cputs(char *);
int /*<<< orphan*/ cputw(int);
int get_hex16(char **);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ test_end(char *);
void go(char *k) {
  int z = get_hex16(&k);
  test_end(k);
  cputs("$GO");
  cputw(z);
  cflush();
  if (cgetw() != z)
    cerr("Invalid reply");
  puts("Started.");
}


x86 assembly (clang, -O0):
<go>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x8(%rbp),%rdi
call   1070 <get_hex16@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1080 <test_end@plt>
lea    0xe58(%rip),%rdi
call   1050 <cputs@plt>
mov    -0xc(%rbp),%edi
call   1040 <cputw@plt>
mov    $0x0,%al
call   1060 <cflush@plt>
mov    $0x0,%al
call   1090 <cgetw@plt>
cmp    -0xc(%rbp),%eax
je     11d8 <go+0x58>
lea    0xe31(%rip),%rdi
call   10a0 <cerr@plt>
lea    0xe33(%rip),%rdi
call   1030 <puts@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<go>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,0x8(%rsp)
lea    0x8(%rsp),%rdi
call   1070 <get_hex16@plt>
mov    %eax,%ebx
mov    0x8(%rsp),%rdi
call   1080 <test_end@plt>
lea    0xe59(%rip),%rdi
call   1050 <cputs@plt>
mov    %ebx,%edi
call   1040 <cputw@plt>
xor    %eax,%eax
call   1060 <cflush@plt>
xor    %eax,%eax
call   1090 <cgetw@plt>
cmp    %ebx,%eax
je     11d1 <go+0x51>
lea    0xe38(%rip),%rdi
call   10a0 <cerr@plt>
lea    0xe3a(%rip),%rdi
call   1030 <puts@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [4 x i8] c"$GO\00"
@.str.1 = [14 x i8] c"Invalid reply\00"
@.str.2 = [9 x i8] c"Started.\00"
define void @go(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = call i32 @get_hex16(i8** %2)
store i32 %4, i32* %3
%5 = load i8*, i8** %2
%6 = call i32 @test_end(i8* %5)
%7 = call i32 @cputs(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* %3
%9 = call i32 @cputw(i32 %8)
%10 = call i32 (...) @cflush()
%11 = call i32 (...) @cgetw()
%12 = load i32, i32* %3
%13 = icmp ne i32 %11, %12
br i1 %13, label %14, label %16
14: ; preds = %1
%15 = call i32 @cerr(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %14, %1
%17 = call i32 @puts(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"$GO\00"
@.str.1 = [14 x i8] c"Invalid reply\00"
@.str.2 = [9 x i8] c"Started.\00"
define void @go(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
%3 = call i32 @get_hex16(i8** %2)
%4 = load i8*, i8** %2
%5 = call i32 @test_end(i8* %4)
%6 = call i32 @cputs(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @cputw(i32 %3)
%8 = call i32 (...) @cflush()
%9 = call i32 (...) @cgetw()
%10 = icmp eq i32 %9, %3
br i1 %10, label %13, label %11
11: ; preds = %1
%12 = call i32 @cerr(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %11, %1
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
ret void
}