#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_in_busy(struct c2interface *);
scalar_t__ c2_write_dr(struct c2interface *, unsigned char);
int c2_pi_write_command(struct c2interface *c2if, unsigned char command) {
  if (c2_write_dr(c2if, command) < 0)
    return -EIO;
  if (c2_poll_in_busy(c2if) < 0)
    return -EIO;
  return 0;
}


x86 assembly (clang, -O0):
<c2_pi_write_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    -0x10(%rbp),%rdi
movzbl -0x11(%rbp),%esi
call   1030 <c2_write_dr@plt>
cmp    $0x0,%rax
jge    115c <c2_pi_write_command+0x3c>
xor    %eax,%eax
mov    0x2e8e(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1189 <c2_pi_write_command+0x69>
mov    -0x10(%rbp),%rdi
call   1040 <c2_poll_in_busy@plt>
cmp    $0x0,%rax
jge    1182 <c2_pi_write_command+0x62>
xor    %eax,%eax
mov    0x2e68(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1189 <c2_pi_write_command+0x69>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<c2_pi_write_command>:
push   %rbx
mov    %rdi,%rbx
call   1030 <c2_write_dr@plt>
test   %rax,%rax
js     1142 <c2_pi_write_command+0x22>
mov    %rbx,%rdi
call   1040 <c2_poll_in_busy@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
js     1142 <c2_pi_write_command+0x22>
pop    %rbx
ret
mov    0x2e97(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.c2interface = type { i32 }
@EIO = global i32 0
define i32 @c2_pi_write_command(%struct.c2interface* %0, i8 zeroext %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 = load i8, i8* %5
%8 = call i64 @c2_write_dr(%struct.c2interface* %6, i8 zeroext %7)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i32, i32* @EIO
%12 = sub nsw i32 0, %11
store i32 %12, i32* %3
br label %21
13: ; preds = %2
%14 = load %struct.c2interface*, %struct.c2interface** %4
%15 = call i64 @c2_poll_in_busy(%struct.c2interface* %14)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = load i32, i32* @EIO
%19 = sub nsw i32 0, %18
store i32 %19, i32* %3
br label %21
20: ; preds = %13
store i32 0, i32* %3
br label %21
21: ; preds = %20, %17, %10
%22 = load i32, i32* %3
ret i32 %22
}

LLVM IR (-O2):
%struct.c2interface = type { i32 }
@EIO = global i32 0
define i32 @c2_pi_write_command(%struct.c2interface* %0, i8 zeroext %1) {
%3 = tail call i64 @c2_write_dr(%struct.c2interface* %0, i8 zeroext %1)
%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_poll_in_busy(%struct.c2interface* %0)
%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
}