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

/* Variables and functions */
int UP3DCOMM_Read(int *, int);
int UP3DCOMM_Write(int *, int);
int /*<<< orphan*/ le32toh(int /*<<< orphan*/);
bool UP3D_GetSystemVar(uint8_t param, int32_t *var) {
  uint8_t UP3D_CMD_76_X[] = {0x76, param};
  uint8_t resp[2048];
  if ((UP3DCOMM_Write(UP3D_CMD_76_X, sizeof(UP3D_CMD_76_X)) !=
       sizeof(UP3D_CMD_76_X)) ||
      (5 != UP3DCOMM_Read(resp, sizeof(resp))) || (6 != resp[4]))
    return false;
  *var = le32toh(*((uint32_t *)resp));
  return true;
}


x86 assembly (clang, -O0):
<UP3D_GetSystemVar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2020,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x76,-0x18(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
lea    -0x18(%rbp),%rdi
mov    $0x8,%esi
call   1030 <UP3DCOMM_Write@plt>
cltq
cmp    $0x8,%rax
jne    119a <UP3D_GetSystemVar+0x6a>
lea    -0x2020(%rbp),%rdi
mov    $0x2000,%esi
call   1050 <UP3DCOMM_Read@plt>
mov    %eax,%ecx
mov    $0x5,%eax
cmp    %ecx,%eax
jne    119a <UP3D_GetSystemVar+0x6a>
mov    $0x6,%eax
cmp    -0x2010(%rbp),%eax
je     11a6 <UP3D_GetSystemVar+0x76>
movl   $0x0,-0x4(%rbp)
jmp    11c0 <UP3D_GetSystemVar+0x90>
mov    -0x2020(%rbp),%edi
call   1040 <le32toh@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<UP3D_GetSystemVar>:
push   %rbp
push   %rbx
sub    $0x2018,%rsp
mov    %rsi,%rbx
movl   $0x76,0x8(%rsp)
mov    %edi,0xc(%rsp)
lea    0x8(%rsp),%rdi
mov    $0x8,%esi
call   1030 <UP3DCOMM_Write@plt>
xor    %ebp,%ebp
cmp    $0x8,%eax
jne    1189 <UP3D_GetSystemVar+0x59>
lea    0x10(%rsp),%rdi
mov    $0x2000,%esi
call   1050 <UP3DCOMM_Read@plt>
cmp    $0x5,%eax
jne    1189 <UP3D_GetSystemVar+0x59>
cmpl   $0x6,0x20(%rsp)
jne    1189 <UP3D_GetSystemVar+0x59>
mov    0x10(%rsp),%edi
call   1040 <le32toh@plt>
mov    %eax,(%rbx)
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x2018,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @UP3D_GetSystemVar(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca [2 x i32]
%7 = alloca [2048 x i32]
store i32 %0, i32* %4
store i32* %1, i32** %5
%8 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
store i32 118, i32* %8
%9 = getelementptr inbounds i32, i32* %8, i64 1
%10 = load i32, i32* %4
store i32 %10, i32* %9
%11 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%12 = call i32 @UP3DCOMM_Write(i32* %11, i32 8)
%13 = sext i32 %12 to i64
%14 = icmp ne i64 %13, 8
br i1 %14, label %23, label %15
15: ; preds = %2
%16 = getelementptr inbounds [2048 x i32], [2048 x i32]* %7, i64 0, i64 0
%17 = call i32 @UP3DCOMM_Read(i32* %16, i32 8192)
%18 = icmp ne i32 5, %17
br i1 %18, label %23, label %19
19: ; preds = %15
%20 = getelementptr inbounds [2048 x i32], [2048 x i32]* %7, i64 0, i64 4
%21 = load i32, i32* %20
%22 = icmp ne i32 6, %21
br i1 %22, label %23, label %24
23: ; preds = %19, %15, %2
store i32 0, i32* %3
br label %29
24: ; preds = %19
%25 = getelementptr inbounds [2048 x i32], [2048 x i32]* %7, i64 0, i64 0
%26 = load i32, i32* %25
%27 = call i32 @le32toh(i32 %26)
%28 = load i32*, i32** %5
store i32 %27, i32* %28
store i32 1, i32* %3
br label %29
29: ; preds = %24, %23
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
define i32 @UP3D_GetSystemVar(i32 %0, i32* nocapture writeonly %1) {
%3 = alloca [2 x i32]
%4 = alloca [2048 x i32]
%5 = bitcast [2 x i32]* %3 to i8*
%6 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
store i32 118, i32* %6
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
store i32 %0, i32* %7
%8 = bitcast [2048 x i32]* %4 to i8*
%9 = call i32 @UP3DCOMM_Write(i32* %6, i32 8)
%10 = icmp eq i32 %9, 8
br i1 %10, label %11, label %22
11: ; preds = %2
%12 = getelementptr inbounds [2048 x i32], [2048 x i32]* %4, i64 0, i64 0
%13 = call i32 @UP3DCOMM_Read(i32* %12, i32 8192)
%14 = icmp ne i32 %13, 5
%15 = getelementptr inbounds [2048 x i32], [2048 x i32]* %4, i64 0, i64 4
%16 = load i32, i32* %15
%17 = icmp ne i32 %16, 6
%18 = select i1 %14, i1 true, i1 %17
br i1 %18, label %22, label %19
19: ; preds = %11
%20 = load i32, i32* %12
%21 = call i32 @le32toh(i32 %20)
store i32 %21, i32* %1
br label %22
22: ; preds = %2, %11, %19
%23 = phi i32 [ 1, %19 ], [ 0, %11 ], [ 0, %2 ]
ret i32 %23
}