#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 */
typedef int uint8_t;
typedef int /*<<< orphan*/ ui8Status;
typedef int int32_t;

/* Variables and functions */
scalar_t__ GetPacket(int *, int *);
scalar_t__ SendPacket(int *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int32_t SendCommand(uint8_t *pui8Command, uint8_t ui8Size) {
  uint8_t ui8Status;
  if (SendPacket(pui8Command, ui8Size, 1) < 0) {
    return (-1);
  }
  ui8Status = 0x23;
  if (SendPacket(&ui8Status, 1, 1) < 0) {
    printf("Failed to Get Status\n");
    return (-1);
  }
  ui8Size = sizeof(ui8Status);
  if (GetPacket(&ui8Status, &ui8Size) < 0) {
    printf("Failed to Get Packet\n");
    return (-1);
  }
  if (ui8Status != 0x40) {
    printf("Failed to get download command Return Code: %04x\n", ui8Status);
    return (-1);
  }
  return (0);
}


x86 assembly (clang, -O0):
<SendCommand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    $0x1,%edx
call   1030 <SendPacket@plt>
cmp    $0x0,%rax
jge    1166 <SendCommand+0x36>
movl   $0xffffffff,-0x4(%rbp)
jmp    1207 <SendCommand+0xd7>
movl   $0x23,-0x18(%rbp)
lea    -0x18(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <SendPacket@plt>
cmp    $0x0,%rax
jge    11a1 <SendCommand+0x71>
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1207 <SendCommand+0xd7>
movl   $0x4,-0x14(%rbp)
lea    -0x18(%rbp),%rdi
lea    -0x14(%rbp),%rsi
call   1050 <GetPacket@plt>
cmp    $0x0,%rax
jge    11d9 <SendCommand+0xa9>
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1207 <SendCommand+0xd7>
cmpl   $0x40,-0x18(%rbp)
je     1200 <SendCommand+0xd0>
mov    -0x18(%rbp),%esi
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1207 <SendCommand+0xd7>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SendCommand>:
push   %rax
mov    $0x1,%edx
call   1040 <SendPacket@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
js     11c4 <SendCommand+0x84>
movl   $0x23,(%rsp)
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
call   1040 <SendPacket@plt>
test   %rax,%rax
js     11aa <SendCommand+0x6a>
movl   $0x4,0x4(%rsp)
mov    %rsp,%rdi
lea    0x4(%rsp),%rsi
call   1060 <GetPacket@plt>
test   %rax,%rax
js     11b3 <SendCommand+0x73>
mov    (%rsp),%esi
xor    %eax,%eax
cmp    $0x40,%esi
je     11c4 <SendCommand+0x84>
lea    0xe5f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11bf <SendCommand+0x7f>
lea    0xe96(%rip),%rdi
jmp    11ba <SendCommand+0x7a>
lea    0xe78(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Failed to Get Status\0A\00"
@.str.1 = [22 x i8] c"Failed to Get Packet\0A\00"
@.str.2 = [50 x i8] c"Failed to get download command Return Code: %04x\0A\00"
define i32 @SendCommand(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
%7 = load i32*, i32** %4
%8 = load i32, i32* %5
%9 = call i64 @SendPacket(i32* %7, i32 %8, i32 1)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 -1, i32* %3
br label %29
12: ; preds = %2
store i32 35, i32* %6
%13 = call i64 @SendPacket(i32* %6, i32 1, i32 1)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %29
17: ; preds = %12
store i32 4, i32* %5
%18 = call i64 @GetPacket(i32* %6, i32* %5)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %29
22: ; preds = %17
%23 = load i32, i32* %6
%24 = icmp ne i32 %23, 64
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = load i32, i32* %6
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0), i32 %26)
store i32 -1, i32* %3
br label %29
28: ; preds = %22
store i32 0, i32* %3
br label %29
29: ; preds = %28, %25, %20, %15, %11
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
@.str.2 = [50 x i8] c"Failed to get download command Return Code: %04x\0A\00"
@str = [21 x i8] c"Failed to Get Packet\00"
@str.3 = [21 x i8] c"Failed to Get Status\00"
define i32 @SendCommand(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = tail call i64 @SendPacket(i32* %0, i32 %1, i32 1)
%7 = icmp slt i64 %6, 0
br i1 %7, label %23, label %8
8: ; preds = %2
store i32 35, i32* %4
%9 = call i64 @SendPacket(i32* %4, i32 1, i32 1)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.3, i64 0, i64 0))
br label %23
13: ; preds = %8
store i32 4, i32* %3
%14 = call i64 @GetPacket(i32* %4, i32* %3)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
br label %23
18: ; preds = %13
%19 = load i32, i32* %4
%20 = icmp eq i32 %19, 64
br i1 %20, label %23, label %21
21: ; preds = %18
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0), i32 %19)
br label %23
23: ; preds = %18, %2, %21, %16, %11
%24 = phi i32 [ -1, %11 ], [ -1, %16 ], [ -1, %21 ], [ -1, %2 ], [ 0, %18 ]
ret i32 %24
}