#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 ENOSPC;
int ETIMEDOUT;
int /*<<< orphan*/ die(char *);
int read_line(int, char *, int, int);
int read_resp(int devfd, char *buf, int maxlen, int timeout_us) {
  int ret;
  ret = read_line(devfd, buf, maxlen, timeout_us);
  if (ret == -ENOSPC)
    die("error: input overflow from VRC0P\n");
  if (ret == -ETIMEDOUT)
    die("error: timeout waiting for command response\n");
  return ret;
}


x86 assembly (clang, -O0):
<read_resp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
call   1030 <read_line@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
xor    %ecx,%ecx
mov    0x2e82(%rip),%rdx
sub    (%rdx),%ecx
cmp    %ecx,%eax
jne    116c <read_resp+0x4c>
lea    0xe99(%rip),%rdi
call   1040 <die@plt>
mov    -0x1c(%rbp),%eax
xor    %ecx,%ecx
mov    0x2e68(%rip),%rdx
sub    (%rdx),%ecx
cmp    %ecx,%eax
jne    118e <read_resp+0x6e>
lea    0xe99(%rip),%rdi
call   1040 <die@plt>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_resp>:
push   %rbx
call   1030 <read_line@plt>
mov    %eax,%ebx
mov    0x2ea9(%rip),%rax
mov    %ebx,%ecx
add    (%rax),%ecx
jne    1141 <read_resp+0x21>
lea    0xec4(%rip),%rdi
call   1040 <die@plt>
mov    0x2e98(%rip),%rax
mov    (%rax),%eax
add    %ebx,%eax
jne    115a <read_resp+0x3a>
lea    0xecd(%rip),%rdi
call   1040 <die@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@ENOSPC = global i32 0
@.str = [34 x i8] c"error: input overflow from VRC0P\0A\00"
@ETIMEDOUT = global i32 0
@.str.1 = [45 x i8] c"error: timeout waiting for command response\0A\00"
define i32 @read_resp(i32 %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%10 = load i32, i32* %5
%11 = load i8*, i8** %6
%12 = load i32, i32* %7
%13 = load i32, i32* %8
%14 = call i32 @read_line(i32 %10, i8* %11, i32 %12, i32 %13)
store i32 %14, i32* %9
%15 = load i32, i32* %9
%16 = load i32, i32* @ENOSPC
%17 = sub nsw i32 0, %16
%18 = icmp eq i32 %15, %17
br i1 %18, label %19, label %21
19: ; preds = %4
%20 = call i32 @die(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
br label %21
21: ; preds = %19, %4
%22 = load i32, i32* %9
%23 = load i32, i32* @ETIMEDOUT
%24 = sub nsw i32 0, %23
%25 = icmp eq i32 %22, %24
br i1 %25, label %26, label %28
26: ; preds = %21
%27 = call i32 @die(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
br label %28
28: ; preds = %26, %21
%29 = load i32, i32* %9
ret i32 %29
}

LLVM IR (-O2):
@ENOSPC = global i32 0
@.str = [34 x i8] c"error: input overflow from VRC0P\0A\00"
@ETIMEDOUT = global i32 0
@.str.1 = [45 x i8] c"error: timeout waiting for command response\0A\00"
define i32 @read_resp(i32 %0, i8* %1, i32 %2, i32 %3) {
%5 = tail call i32 @read_line(i32 %0, i8* %1, i32 %2, i32 %3)
%6 = load i32, i32* @ENOSPC
%7 = sub nsw i32 0, %6
%8 = icmp eq i32 %5, %7
br i1 %8, label %9, label %11
9: ; preds = %4
%10 = tail call i32 @die(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %4
%12 = load i32, i32* @ETIMEDOUT
%13 = sub nsw i32 0, %12
%14 = icmp eq i32 %5, %13
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = tail call i32 @die(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %15, %11
ret i32 %5
}