#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_76_X;

/* Variables and functions */
int UP3DCOMM_Read(int *, int);
int UP3DCOMM_Write(int *, int);
int /*<<< orphan*/ le32toh(int /*<<< orphan*/);
uint32_t UP3D_GetParameter(uint8_t param) {
  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 0;
  return le32toh(*((uint32_t *)resp));
}


x86 assembly (clang, -O0):
<UP3D_GetParameter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2010,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x76,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
lea    -0x10(%rbp),%rdi
mov    $0x8,%esi
call   1030 <UP3DCOMM_Write@plt>
cltq
cmp    $0x8,%rax
jne    1196 <UP3D_GetParameter+0x66>
lea    -0x2010(%rbp),%rdi
mov    $0x2000,%esi
call   1050 <UP3DCOMM_Read@plt>
mov    %eax,%ecx
mov    $0x5,%eax
cmp    %ecx,%eax
jne    1196 <UP3D_GetParameter+0x66>
mov    $0x6,%eax
cmp    -0x2000(%rbp),%eax
je     11a2 <UP3D_GetParameter+0x72>
movl   $0x0,-0x4(%rbp)
jmp    11b0 <UP3D_GetParameter+0x80>
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_GetParameter>:
push   %rbx
sub    $0x2010,%rsp
movl   $0x76,0x8(%rsp)
mov    %edi,0xc(%rsp)
lea    0x8(%rsp),%rdi
mov    $0x8,%esi
call   1030 <UP3DCOMM_Write@plt>
xor    %ebx,%ebx
cmp    $0x8,%eax
jne    1180 <UP3D_GetParameter+0x50>
lea    0x10(%rsp),%rdi
mov    $0x2000,%esi
call   1050 <UP3DCOMM_Read@plt>
cmp    $0x5,%eax
jne    1180 <UP3D_GetParameter+0x50>
cmpl   $0x6,0x20(%rsp)
jne    1180 <UP3D_GetParameter+0x50>
mov    0x10(%rsp),%edi
call   1040 <le32toh@plt>
mov    %eax,%ebx
mov    %ebx,%eax
add    $0x2010,%rsp
pop    %rbx
ret

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

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