#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 */
struct c2interface {
  int dummy;
};

/* Variables and functions */
int EIO;
scalar_t__ c2_poll_out_ready(struct c2interface *);
scalar_t__ c2_read_dr(struct c2interface *, unsigned char *);
int c2_pi_get_data(struct c2interface *c2if, unsigned char *data) {
  if (c2_poll_out_ready(c2if) < 0)
    return -EIO;
  if (c2_read_dr(c2if, data) < 0)
    return -EIO;
  return 0;
}


x86 assembly (clang, -O0):
<c2_pi_get_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <c2_poll_out_ready@plt>
cmp    $0x0,%rax
jge    1156 <c2_pi_get_data+0x36>
xor    %eax,%eax
mov    0x2e94(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1187 <c2_pi_get_data+0x67>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <c2_read_dr@plt>
cmp    $0x0,%rax
jge    1180 <c2_pi_get_data+0x60>
xor    %eax,%eax
mov    0x2e6a(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1187 <c2_pi_get_data+0x67>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<c2_pi_get_data>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <c2_poll_out_ready@plt>
test   %rax,%rax
js     1149 <c2_pi_get_data+0x29>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <c2_read_dr@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jns    1154 <c2_pi_get_data+0x34>
mov    0x2e90(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.c2interface = type { i32 }
@EIO = global i32 0
define i32 @c2_pi_get_data(%struct.c2interface* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.c2interface*
%5 = alloca i8*
store %struct.c2interface* %0, %struct.c2interface** %4
store i8* %1, i8** %5
%6 = load %struct.c2interface*, %struct.c2interface** %4
%7 = call i64 @c2_poll_out_ready(%struct.c2interface* %6)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load i32, i32* @EIO
%11 = sub nsw i32 0, %10
store i32 %11, i32* %3
br label %21
12: ; preds = %2
%13 = load %struct.c2interface*, %struct.c2interface** %4
%14 = load i8*, i8** %5
%15 = call i64 @c2_read_dr(%struct.c2interface* %13, i8* %14)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = load i32, i32* @EIO
%19 = sub nsw i32 0, %18
store i32 %19, i32* %3
br label %21
20: ; preds = %12
store i32 0, i32* %3
br label %21
21: ; preds = %20, %17, %9
%22 = load i32, i32* %3
ret i32 %22
}

LLVM IR (-O2):
%struct.c2interface = type { i32 }
@EIO = global i32 0
define i32 @c2_pi_get_data(%struct.c2interface* %0, i8* %1) {
%3 = tail call i64 @c2_poll_out_ready(%struct.c2interface* %0)
%4 = icmp slt i64 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = load i32, i32* @EIO
%7 = sub nsw i32 0, %6
br label %14
8: ; preds = %2
%9 = tail call i64 @c2_read_dr(%struct.c2interface* %0, i8* %1)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = load i32, i32* @EIO
%13 = sub nsw i32 0, %12
br label %14
14: ; preds = %8, %11, %5
%15 = phi i32 [ %7, %5 ], [ %13, %11 ], [ 0, %8 ]
ret i32 %15
}