#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*/ uint32_t;
typedef int /*<<< orphan*/ resp;
typedef int /*<<< orphan*/ UP3D_CMD_46;

/* Variables and functions */
int UP3DCOMM_Read(int *, int);
int UP3DCOMM_Write(int const *, int);
int /*<<< orphan*/ le32toh(int /*<<< orphan*/);
uint32_t UP3D_GetFreeBlocks() {
  static const uint8_t UP3D_CMD_46[] = {0x46};
  uint8_t resp[2048];
  if ((UP3DCOMM_Write(UP3D_CMD_46, sizeof(UP3D_CMD_46)) !=
       sizeof(UP3D_CMD_46)) ||
      (5 != UP3DCOMM_Read(resp, sizeof(resp))) || (6 != resp[4]))
    return 0;
  return le32toh(*((uint32_t *)resp));
}


x86 assembly (clang, -O0):
<UP3D_GetFreeBlocks>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2010,%rsp
lea    0xebe(%rip),%rdi
mov    $0x4,%esi
call   1030 <UP3DCOMM_Write@plt>
cltq
cmp    $0x4,%rax
jne    1189 <UP3D_GetFreeBlocks+0x59>
lea    -0x2010(%rbp),%rdi
mov    $0x2000,%esi
call   1050 <UP3DCOMM_Read@plt>
mov    %eax,%ecx
mov    $0x5,%eax
cmp    %ecx,%eax
jne    1189 <UP3D_GetFreeBlocks+0x59>
mov    $0x6,%eax
cmp    -0x2000(%rbp),%eax
je     1195 <UP3D_GetFreeBlocks+0x65>
movl   $0x0,-0x4(%rbp)
jmp    11a3 <UP3D_GetFreeBlocks+0x73>
mov    -0x2010(%rbp),%edi
call   1040 <le32toh@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2010,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<UP3D_GetFreeBlocks>:
push   %rbx
sub    $0x2000,%rsp
lea    0xec1(%rip),%rdi
mov    $0x4,%esi
call   1030 <UP3DCOMM_Write@plt>
xor    %ebx,%ebx
cmp    $0x4,%eax
jne    1173 <UP3D_GetFreeBlocks+0x43>
mov    %rsp,%rdi
mov    $0x2000,%esi
call   1050 <UP3DCOMM_Read@plt>
cmp    $0x5,%eax
jne    1173 <UP3D_GetFreeBlocks+0x43>
cmpl   $0x6,0x10(%rsp)
jne    1173 <UP3D_GetFreeBlocks+0x43>
mov    (%rsp),%edi
call   1040 <le32toh@plt>
mov    %eax,%ebx
mov    %ebx,%eax
add    $0x2000,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@UP3D_GetFreeBlocks.UP3D_CMD_46 = internal constant [1 x i32] [i32 70]
define i32 @UP3D_GetFreeBlocks() {
%1 = alloca i32
%2 = alloca [2048 x i32]
%3 = call i32 @UP3DCOMM_Write(i32* getelementptr inbounds ([1 x i32], [1 x i32]* @UP3D_GetFreeBlocks.UP3D_CMD_46, i64 0, i64 0), i32 4)
%4 = sext i32 %3 to i64
%5 = icmp ne i64 %4, 4
br i1 %5, label %14, label %6
6: ; preds = %0
%7 = getelementptr inbounds [2048 x i32], [2048 x i32]* %2, i64 0, i64 0
%8 = call i32 @UP3DCOMM_Read(i32* %7, i32 8192)
%9 = icmp ne i32 5, %8
br i1 %9, label %14, label %10
10: ; preds = %6
%11 = getelementptr inbounds [2048 x i32], [2048 x i32]* %2, i64 0, i64 4
%12 = load i32, i32* %11
%13 = icmp ne i32 6, %12
br i1 %13, label %14, label %15
14: ; preds = %10, %6, %0
store i32 0, i32* %1
br label %19
15: ; preds = %10
%16 = getelementptr inbounds [2048 x i32], [2048 x i32]* %2, i64 0, i64 0
%17 = load i32, i32* %16
%18 = call i32 @le32toh(i32 %17)
store i32 %18, i32* %1
br label %19
19: ; preds = %15, %14
%20 = load i32, i32* %1
ret i32 %20
}

LLVM IR (-O2):
@UP3D_GetFreeBlocks.UP3D_CMD_46 = internal constant [1 x i32] [i32 70]
define i32 @UP3D_GetFreeBlocks() {
%1 = alloca [2048 x i32]
%2 = bitcast [2048 x i32]* %1 to i8*
%3 = tail call i32 @UP3DCOMM_Write(i32* getelementptr inbounds ([1 x i32], [1 x i32]* @UP3D_GetFreeBlocks.UP3D_CMD_46, i64 0, i64 0), i32 4)
%4 = icmp eq i32 %3, 4
br i1 %4, label %5, label %16
5: ; preds = %0
%6 = getelementptr inbounds [2048 x i32], [2048 x i32]* %1, i64 0, i64 0
%7 = call i32 @UP3DCOMM_Read(i32* %6, i32 8192)
%8 = icmp ne i32 %7, 5
%9 = getelementptr inbounds [2048 x i32], [2048 x i32]* %1, i64 0, i64 4
%10 = load i32, i32* %9
%11 = icmp ne i32 %10, 6
%12 = select i1 %8, i1 true, i1 %11
br i1 %12, label %16, label %13
13: ; preds = %5
%14 = load i32, i32* %6
%15 = call i32 @le32toh(i32 %14)
br label %16
16: ; preds = %0, %5, %13
%17 = phi i32 [ %15, %13 ], [ 0, %5 ], [ 0, %0 ]
ret i32 %17
}