#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_pi_check_command(struct c2interface *);
scalar_t__ c2_pi_get_data(struct c2interface *, unsigned char *);
scalar_t__ c2_pi_write_command(struct c2interface *, unsigned char);
int c2_pi_command(struct c2interface *c2if, unsigned char command, int verify,
                  unsigned char *result) {
  if (c2_pi_write_command(c2if, command) < 0)
    return -EIO;
  if (!verify)
    return 0;
  if (c2_pi_check_command(c2if) < 0)
    return -EIO;
  if (!result)
    return 0;
  if (c2_pi_get_data(c2if, result) < 0)
    return -EIO;
  return 0;
}


x86 assembly (clang, -O0):
<c2_pi_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
movzbl -0x11(%rbp),%esi
call   1050 <c2_pi_write_command@plt>
cmp    $0x0,%rax
jge    1173 <c2_pi_command+0x43>
xor    %eax,%eax
mov    0x2e77(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11f7 <c2_pi_command+0xc7>
cmpl   $0x0,-0x18(%rbp)
jne    1189 <c2_pi_command+0x59>
movl   $0x0,-0x4(%rbp)
jmp    11f7 <c2_pi_command+0xc7>
mov    -0x10(%rbp),%rdi
call   1030 <c2_pi_check_command@plt>
cmp    $0x0,%rax
jge    11af <c2_pi_command+0x7f>
xor    %eax,%eax
mov    0x2e3b(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11f7 <c2_pi_command+0xc7>
cmpq   $0x0,-0x20(%rbp)
jne    11c6 <c2_pi_command+0x96>
movl   $0x0,-0x4(%rbp)
jmp    11f7 <c2_pi_command+0xc7>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <c2_pi_get_data@plt>
cmp    $0x0,%rax
jge    11f0 <c2_pi_command+0xc0>
xor    %eax,%eax
mov    0x2dfa(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11f7 <c2_pi_command+0xc7>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<c2_pi_command>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %edx,%r15d
mov    %rdi,%rbx
call   1050 <c2_pi_write_command@plt>
test   %rax,%rax
js     1173 <c2_pi_command+0x43>
xor    %ebp,%ebp
test   %r15d,%r15d
je     117e <c2_pi_command+0x4e>
mov    %rbx,%rdi
call   1030 <c2_pi_check_command@plt>
test   %rax,%rax
js     1173 <c2_pi_command+0x43>
test   %r14,%r14
je     117e <c2_pi_command+0x4e>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <c2_pi_get_data@plt>
test   %rax,%rax
jns    117e <c2_pi_command+0x4e>
mov    0x2e66(%rip),%rax
xor    %ebp,%ebp
sub    (%rax),%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.c2interface = type { i32 }
@EIO = global i32 0
define i32 @c2_pi_command(%struct.c2interface* %0, i8 zeroext %1, i32 %2, i8* %3) {
%5 = alloca i32
%6 = alloca %struct.c2interface*
%7 = alloca i8
%8 = alloca i32
%9 = alloca i8*
store %struct.c2interface* %0, %struct.c2interface** %6
store i8 %1, i8* %7
store i32 %2, i32* %8
store i8* %3, i8** %9
%10 = load %struct.c2interface*, %struct.c2interface** %6
%11 = load i8, i8* %7
%12 = call i64 @c2_pi_write_command(%struct.c2interface* %10, i8 zeroext %11)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %4
%15 = load i32, i32* @EIO
%16 = sub nsw i32 0, %15
store i32 %16, i32* %5
br label %41
17: ; preds = %4
%18 = load i32, i32* %8
%19 = icmp ne i32 %18, 0
br i1 %19, label %21, label %20
20: ; preds = %17
store i32 0, i32* %5
br label %41
21: ; preds = %17
%22 = load %struct.c2interface*, %struct.c2interface** %6
%23 = call i64 @c2_pi_check_command(%struct.c2interface* %22)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = load i32, i32* @EIO
%27 = sub nsw i32 0, %26
store i32 %27, i32* %5
br label %41
28: ; preds = %21
%29 = load i8*, i8** %9
%30 = icmp ne i8* %29, null
br i1 %30, label %32, label %31
31: ; preds = %28
store i32 0, i32* %5
br label %41
32: ; preds = %28
%33 = load %struct.c2interface*, %struct.c2interface** %6
%34 = load i8*, i8** %9
%35 = call i64 @c2_pi_get_data(%struct.c2interface* %33, i8* %34)
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %32
%38 = load i32, i32* @EIO
%39 = sub nsw i32 0, %38
store i32 %39, i32* %5
br label %41
40: ; preds = %32
store i32 0, i32* %5
br label %41
41: ; preds = %40, %37, %31, %25, %20, %14
%42 = load i32, i32* %5
ret i32 %42
}

LLVM IR (-O2):
%struct.c2interface = type { i32 }
@EIO = global i32 0
define i32 @c2_pi_command(%struct.c2interface* %0, i8 zeroext %1, i32 %2, i8* %3) {
%5 = tail call i64 @c2_pi_write_command(%struct.c2interface* %0, i8 zeroext %1)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %4
%8 = load i32, i32* @EIO
%9 = sub nsw i32 0, %8
br label %26
10: ; preds = %4
%11 = icmp eq i32 %2, 0
br i1 %11, label %26, label %12
12: ; preds = %10
%13 = tail call i64 @c2_pi_check_command(%struct.c2interface* %0)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load i32, i32* @EIO
%17 = sub nsw i32 0, %16
br label %26
18: ; preds = %12
%19 = icmp eq i8* %3, null
br i1 %19, label %26, label %20
20: ; preds = %18
%21 = tail call i64 @c2_pi_get_data(%struct.c2interface* %0, i8* %3)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = load i32, i32* @EIO
%25 = sub nsw i32 0, %24
br label %26
26: ; preds = %20, %18, %10, %23, %15, %7
%27 = phi i32 [ %9, %7 ], [ %17, %15 ], [ %25, %23 ], [ 0, %10 ], [ 0, %18 ], [ 0, %20 ]
ret i32 %27
}