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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ print_error(char *);
scalar_t__ read_response(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ stderr;
bool check_response(FILE *stream) {
  char response[1024];
  size_t rx = fread(response, 1, 1, stream);
  if (rx != 1)
    return ({
      print_error("Unexpected server disconnect");
      false;
    });
  else if (*response == '\0')
    return true;
  else {
    if (read_response(stream, response + 1, sizeof(response) - 1))
      fprintf(stderr, "%s", response);
    return false;
  }
}


x86 assembly (clang, -O0):
<check_response>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
mov    %rax,-0x418(%rbp)
cmpq   $0x1,-0x418(%rbp)
01
je     119f <check_response+0x5f>
lea    0xe7e(%rip),%rdi
call   1040 <print_error@plt>
movl   $0x0,-0x41c(%rbp)
mov    -0x41c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1201 <check_response+0xc1>
movsbl -0x410(%rbp),%eax
cmp    $0x0,%eax
jne    11bb <check_response+0x7b>
movl   $0x1,-0x4(%rbp)
jmp    1201 <check_response+0xc1>
mov    -0x10(%rbp),%rdi
lea    -0x410(%rbp),%rsi
add    $0x1,%rsi
mov    $0x3ff,%edx
call   1060 <read_response@plt>
cmp    $0x0,%rax
je     11fa <check_response+0xba>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
lea    -0x410(%rbp),%rdx
lea    0xe28(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_response>:
push   %rbp
push   %rbx
sub    $0x408,%rsp
mov    %rdi,%rbx
mov    %rsp,%rdi
mov    $0x1,%ebp
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
cmp    $0x1,%rax
jne    11a5 <check_response+0x65>
cmpb   $0x0,(%rsp)
je     11b3 <check_response+0x73>
lea    0x1(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x3ff,%edx
call   1060 <read_response@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     11b3 <check_response+0x73>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
lea    0xe82(%rip),%rsi
mov    %rsp,%rdx
call   1050 <fprintf@plt>
jmp    11b3 <check_response+0x73>
lea    0xe54(%rip),%rdi
call   1040 <print_error@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x408,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [29 x i8] c"Unexpected server disconnect\00"
@stderr = global i32 0
@.str.1 = [3 x i8] c"%s\00"
define i32 @check_response(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca [1024 x i8]
%5 = alloca i64
%6 = alloca i32
store i32* %0, i32** %3
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%8 = load i32*, i32** %3
%9 = call i64 @fread(i8* %7, i32 1, i32 1, i32* %8)
store i64 %9, i64* %5
%10 = load i64, i64* %5
%11 = icmp ne i64 %10, 1
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = call i32 @print_error(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %6
%14 = load i32, i32* %6
store i32 %14, i32* %2
br label %32
15: ; preds = %1
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %15
store i32 1, i32* %2
br label %32
21: ; preds = %15
%22 = load i32*, i32** %3
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%24 = getelementptr inbounds i8, i8* %23, i64 1
%25 = call i64 @read_response(i32* %22, i8* %24, i32 1023)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %21
%28 = load i32, i32* @stderr
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%30 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %29)
br label %31
31: ; preds = %27, %21
store i32 0, i32* %2
br label %32
32: ; preds = %31, %20, %12
%33 = load i32, i32* %2
ret i32 %33
}

LLVM IR (-O2):
@.str = [29 x i8] c"Unexpected server disconnect\00"
@stderr = global i32 0
@.str.1 = [3 x i8] c"%s\00"
define i32 @check_response(i32* %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = call i64 @fread(i8* %3, i32 1, i32 1, i32* %0)
%5 = icmp eq i64 %4, 1
br i1 %5, label %8, label %6
6: ; preds = %1
%7 = tail call i32 @print_error(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %18
8: ; preds = %1
%9 = load i8, i8* %3
%10 = icmp eq i8 %9, 0
br i1 %10, label %18, label %11
11: ; preds = %8
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 1
%13 = call i64 @read_response(i32* %0, i8* %12, i32 1023)
%14 = icmp eq i64 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %11
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
br label %18
18: ; preds = %11, %15, %8, %6
%19 = phi i32 [ 0, %6 ], [ 1, %8 ], [ 0, %15 ], [ 0, %11 ]
ret i32 %19
}