#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, int,
                           char const *, ...);
int /*<<< orphan*/ fwrite_diff(int /*<<< orphan*/, char *, int, char *, int);
int ide_get_sense_code();
scalar_t__ memcmp(char *, char *, int);
int read_pio(char *, int);
int send_packet_command(char const *);
int /*<<< orphan*/ stderr;
int ide_test_packet_ok(const char *file, int line, const char *func,
                       const char *cmd, char *expect, int expect_len) {
  char buf[expect_len];
  int status = send_packet_command(cmd);
  if (status != 0) {
    return status;
  }
  status = (unsigned int)(*((volatile unsigned char *)(0xA05F7000 + 0x018)));
  if (status & 1) {
    status = ide_get_sense_code();
    fprintf(stderr, "Assertion failed at %s:%d %s(): Unexpected error %04X\n",
            file, line, func, status);
    return -1;
  }
  status = read_pio(buf, expect_len);
  if (status != 0) {
    return status;
  }
  if (expect != NULL && memcmp(expect, buf, expect_len) != 0) {
    fprintf(stderr,
            "Assertion failed at %s:%d %s(): Results differ from expected:\n",
            file, line, func);
    fwrite_diff(stderr, expect, expect_len, buf, expect_len);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<ide_test_packet_ok>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9d,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x48(%rbp)
mov    -0x28(%rbp),%rdi
call   1080 <send_packet_command@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
je     11cd <ide_test_packet_ok+0x6d>
mov    -0x4c(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x50(%rbp)
jmp    12dc <ide_test_packet_ok+0x17c>
mov    $0xa05f7018,%eax
mov    (%rax),%al
movzbl %al,%eax
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     122c <ide_test_packet_ok+0xcc>
mov    $0x0,%al
call   1060 <ide_get_sense_code@plt>
mov    %eax,-0x4c(%rbp)
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    -0x20(%rbp),%r8
mov    -0x4c(%rbp),%r9d
lea    0xdee(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x50(%rbp)
jmp    12dc <ide_test_packet_ok+0x17c>
mov    -0x58(%rbp),%rdi
mov    -0x34(%rbp),%esi
call   1070 <read_pio@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
je     1257 <ide_test_packet_ok+0xf7>
mov    -0x4c(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x50(%rbp)
jmp    12dc <ide_test_packet_ok+0x17c>
cmpq   $0x0,-0x30(%rbp)
je     12ce <ide_test_packet_ok+0x16e>
mov    -0x58(%rbp),%rsi
mov    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%edx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
je     12ce <ide_test_packet_ok+0x16e>
mov    0x2d5d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    -0x20(%rbp),%r8
lea    0xda0(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x58(%rbp),%rcx
mov    0x2d37(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rsi
mov    -0x34(%rbp),%edx
mov    -0x34(%rbp),%r8d
call   1030 <fwrite_diff@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x50(%rbp)
jmp    12dc <ide_test_packet_ok+0x17c>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x50(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ide_test_packet_ok>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9d,%ebx
mov    %r8,%r15
mov    %rdx,-0x38(%rbp)
mov    %esi,-0x2c(%rbp)
mov    %rdi,%r12
mov    %r9d,%eax
mov    %rsp,%r14
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    %rcx,%rdi
call   1080 <send_packet_command@plt>
mov    %eax,%r13d
test   %eax,%eax
jne    124b <ide_test_packet_ok+0xeb>
mov    $0xa05f7018,%eax
testb  $0x1,(%rax)
jne    121a <ide_test_packet_ok+0xba>
mov    %r14,%rdi
mov    %ebx,%esi
call   1070 <read_pio@plt>
mov    %eax,%r13d
test   %eax,%eax
jne    124b <ide_test_packet_ok+0xeb>
xor    %r13d,%r13d
test   %r15,%r15
je     124b <ide_test_packet_ok+0xeb>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1040 <memcmp@plt>
test   %rax,%rax
je     124b <ide_test_packet_ok+0xeb>
mov    0x2df8(%rip),%r13
mov    0x0(%r13),%edi
lea    0xe44(%rip),%rsi
mov    %r12,%rdx
mov    -0x2c(%rbp),%ecx
mov    -0x38(%rbp),%r8
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x0(%r13),%edi
mov    %r15,%rsi
mov    %ebx,%edx
mov    %r14,%rcx
mov    %ebx,%r8d
call   1030 <fwrite_diff@plt>
jmp    1245 <ide_test_packet_ok+0xe5>
xor    %eax,%eax
call   1060 <ide_get_sense_code@plt>
mov    0x2db8(%rip),%rcx
mov    (%rcx),%edi
lea    0xdcf(%rip),%rsi
mov    %r12,%rdx
mov    -0x2c(%rbp),%ecx
mov    -0x38(%rbp),%r8
mov    %eax,%r9d
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%r13d
mov    %r13d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [55 x i8] c"Assertion failed at %s:%d %s(): Unexpected error %04X\0A\00"
@.str.1 = [63 x i8] c"Assertion failed at %s:%d %s(): Results differ from expected:\0A\00"
define i32 @ide_test_packet_ok(i8* %0, i32 %1, i8* %2, i8* %3, i8* %4, i32 %5) {
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i64
%16 = alloca i32
%17 = alloca i32
store i8* %0, i8** %8
store i32 %1, i32* %9
store i8* %2, i8** %10
store i8* %3, i8** %11
store i8* %4, i8** %12
store i32 %5, i32* %13
%18 = load i32, i32* %13
%19 = zext i32 %18 to i64
%20 = call i8* @llvm.stacksave()
store i8* %20, i8** %14
%21 = alloca i8, i64 %19
store i64 %19, i64* %15
%22 = load i8*, i8** %11
%23 = call i32 @send_packet_command(i8* %22)
store i32 %23, i32* %16
%24 = load i32, i32* %16
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %6
%27 = load i32, i32* %16
store i32 %27, i32* %7
store i32 1, i32* %17
br label %69
28: ; preds = %6
%29 = load volatile i8, i8* inttoptr (i64 2690609176 to i8*)
%30 = zext i8 %29 to i32
store i32 %30, i32* %16
%31 = load i32, i32* %16
%32 = and i32 %31, 1
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %42
34: ; preds = %28
%35 = call i32 (...) @ide_get_sense_code()
store i32 %35, i32* %16
%36 = load i32, i32* @stderr
%37 = load i8*, i8** %8
%38 = load i32, i32* %9
%39 = load i8*, i8** %10
%40 = load i32, i32* %16
%41 = call i32 (i32, i8*, i8*, i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i8* %37, i32 %38, i8* %39, i32 %40)
store i32 -1, i32* %7
store i32 1, i32* %17
br label %69
42: ; preds = %28
%43 = load i32, i32* %13
%44 = call i32 @read_pio(i8* %21, i32 %43)
store i32 %44, i32* %16
%45 = load i32, i32* %16
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %42
%48 = load i32, i32* %16
store i32 %48, i32* %7
store i32 1, i32* %17
br label %69
49: ; preds = %42
%50 = load i8*, i8** %12
%51 = icmp ne i8* %50, null
br i1 %51, label %52, label %68
52: ; preds = %49
%53 = load i8*, i8** %12
%54 = load i32, i32* %13
%55 = call i64 @memcmp(i8* %53, i8* %21, i32 %54)
%56 = icmp ne i64 %55, 0
br i1 %56, label %57, label %68
57: ; preds = %52
%58 = load i32, i32* @stderr
%59 = load i8*, i8** %8
%60 = load i32, i32* %9
%61 = load i8*, i8** %10
%62 = call i32 (i32, i8*, i8*, i32, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.1, i64 0, i64 0), i8* %59, i32 %60, i8* %61)
%63 = load i32, i32* @stderr
%64 = load i8*, i8** %12
%65 = load i32, i32* %13
%66 = load i32, i32* %13
%67 = call i32 @fwrite_diff(i32 %63, i8* %64, i32 %65, i8* %21, i32 %66)
store i32 -1, i32* %7
store i32 1, i32* %17
br label %69
68: ; preds = %52, %49
store i32 0, i32* %7
store i32 1, i32* %17
br label %69
69: ; preds = %68, %57, %47, %34, %26
%70 = load i8*, i8** %14
%71 = load i32, i32* %7
ret i32 %71
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [55 x i8] c"Assertion failed at %s:%d %s(): Unexpected error %04X\0A\00"
@.str.1 = [63 x i8] c"Assertion failed at %s:%d %s(): Results differ from expected:\0A\00"
define i32 @ide_test_packet_ok(i8* %0, i32 %1, i8* %2, i8* %3, i8* %4, i32 %5) {
%7 = zext i32 %5 to i64
%8 = alloca i8, i64 %7
%9 = tail call i32 @send_packet_command(i8* %3)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %32
11: ; preds = %6
%12 = load volatile i8, i8* inttoptr (i64 2690609176 to i8*)
%13 = and i8 %12, 1
%14 = icmp eq i8 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %11
%16 = tail call i32 (...) @ide_get_sense_code()
%17 = load i32, i32* @stderr
%18 = tail call i32 (i32, i8*, i8*, i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %1, i8* %2, i32 %16)
br label %32
19: ; preds = %11
%20 = call i32 @read_pio(i8* %8, i32 %5)
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %32
22: ; preds = %19
%23 = icmp eq i8* %4, null
br i1 %23, label %32, label %24
24: ; preds = %22
%25 = call i64 @memcmp(i8* %4, i8* %8, i32 %5)
%26 = icmp eq i64 %25, 0
br i1 %26, label %32, label %27
27: ; preds = %24
%28 = load i32, i32* @stderr
%29 = call i32 (i32, i8*, i8*, i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 %1, i8* %2)
%30 = load i32, i32* @stderr
%31 = call i32 @fwrite_diff(i32 %30, i8* %4, i32 %5, i8* %8, i32 %5)
br label %32
32: ; preds = %22, %24, %19, %6, %27, %15
%33 = phi i32 [ -1, %15 ], [ -1, %27 ], [ %9, %6 ], [ %20, %19 ], [ 0, %24 ], [ 0, %22 ]
ret i32 %33
}