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

/* Variables and functions */
int /*<<< orphan*/ exit_error(char *);
int readline(int, char *, int);
scalar_t__ strncmp(char *, char *, int);
void check_status(int fd) {
  char buffer[1024];
  ssize_t r;
  r = readline(fd, buffer, sizeof(buffer));
  if (r == 0)
    exit_error("remote end closed connection unexpectedly\n");
  if (r < 0)
    exit_error("read status");
  if (r < 2)
    exit_error("response too short");
  if (!strncmp("E ", buffer, 2))
    exit_error(buffer + 2);
  if (strncmp("OK", buffer, 2))
    exit_error("unexpected reply");
}


x86 assembly (clang, -O0):
<check_status>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1040 <readline@plt>
mov    %eax,-0x414(%rbp)
cmpl   $0x0,-0x414(%rbp)
jne    1171 <check_status+0x41>
lea    0xe94(%rip),%rdi
call   1050 <exit_error@plt>
cmpl   $0x0,-0x414(%rbp)
jge    118a <check_status+0x5a>
lea    0xea6(%rip),%rdi
call   1050 <exit_error@plt>
cmpl   $0x2,-0x414(%rbp)
jge    11a3 <check_status+0x73>
lea    0xe99(%rip),%rdi
call   1050 <exit_error@plt>
lea    -0x410(%rbp),%rsi
lea    0xe99(%rip),%rdi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11d5 <check_status+0xa5>
lea    -0x410(%rbp),%rdi
add    $0x2,%rdi
call   1050 <exit_error@plt>
lea    -0x410(%rbp),%rsi
lea    0xe6a(%rip),%rdi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     1203 <check_status+0xd3>
lea    0xe52(%rip),%rdi
call   1050 <exit_error@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_status>:
sub    $0x408,%rsp
mov    %rsp,%rsi
mov    $0x400,%edx
call   1040 <readline@plt>
test   %eax,%eax
je     1151 <check_status+0x21>
js     115a <check_status+0x2a>
cmp    $0x2,%eax
jb     1166 <check_status+0x36>
jmp    1172 <check_status+0x42>
lea    0xea8(%rip),%rdi
jmp    1161 <check_status+0x31>
lea    0xeca(%rip),%rdi
call   1050 <exit_error@plt>
lea    0xeca(%rip),%rdi
call   1050 <exit_error@plt>
lea    0xed1(%rip),%rdi
mov    %rsp,%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1195 <check_status+0x65>
lea    0x2(%rsp),%rdi
call   1050 <exit_error@plt>
lea    0xeb1(%rip),%rdi
mov    %rsp,%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11ba <check_status+0x8a>
lea    0xe9b(%rip),%rdi
call   1050 <exit_error@plt>
add    $0x408,%rsp
ret

LLVM IR (-O0):
@.str = [43 x i8] c"remote end closed connection unexpectedly\0A\00"
@.str.1 = [12 x i8] c"read status\00"
@.str.2 = [19 x i8] c"response too short\00"
@.str.3 = [3 x i8] c"E \00"
@.str.4 = [3 x i8] c"OK\00"
@.str.5 = [17 x i8] c"unexpected reply\00"
define void @check_status(i32 %0) {
%2 = alloca i32
%3 = alloca [1024 x i8]
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%7 = call i32 @readline(i32 %5, i8* %6, i32 1024)
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i32 @exit_error(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %1
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 @exit_error(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %15, %12
%18 = load i32, i32* %4
%19 = icmp slt i32 %18, 2
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = call i32 @exit_error(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %22
22: ; preds = %20, %17
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%24 = call i64 @strncmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %23, i32 2)
%25 = icmp ne i64 %24, 0
br i1 %25, label %30, label %26
26: ; preds = %22
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%28 = getelementptr inbounds i8, i8* %27, i64 2
%29 = call i32 @exit_error(i8* %28)
br label %30
30: ; preds = %26, %22
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%32 = call i64 @strncmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %31, i32 2)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %30
%35 = call i32 @exit_error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
br label %36
36: ; preds = %34, %30
ret void
}

LLVM IR (-O2):
@.str = [43 x i8] c"remote end closed connection unexpectedly\0A\00"
@.str.1 = [12 x i8] c"read status\00"
@.str.2 = [19 x i8] c"response too short\00"
@.str.3 = [3 x i8] c"E \00"
@.str.4 = [3 x i8] c"OK\00"
@.str.5 = [17 x i8] c"unexpected reply\00"
define void @check_status(i32 %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = call i32 @readline(i32 %0, i8* %3, i32 1024)
%5 = icmp eq i32 %4, 0
br i1 %5, label %10, label %6
6: ; preds = %1
%7 = icmp slt i32 %4, 0
br i1 %7, label %10, label %8
8: ; preds = %6
%9 = icmp ult i32 %4, 2
br i1 %9, label %13, label %15
10: ; preds = %6, %1
%11 = phi i8* [ getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), %6 ]
%12 = call i32 @exit_error(i8* %11)
br label %13
13: ; preds = %10, %8
%14 = call i32 @exit_error(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %15
15: ; preds = %13, %8
%16 = call i64 @strncmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %3, i32 2)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 2
%20 = call i32 @exit_error(i8* %19)
br label %21
21: ; preds = %18, %15
%22 = call i64 @strncmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %3, i32 2)
%23 = icmp eq i64 %22, 0
br i1 %23, label %26, label %24
24: ; preds = %21
%25 = call i32 @exit_error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
br label %26
26: ; preds = %24, %21
ret void
}