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

/* Variables and functions */
int UP3DCOMM_Read(int *, int);
int UP3DCOMM_Write(int *, int);
int /*<<< orphan*/ memcpy(int *, int /*<<< orphan*/ *, int);
bool UP3D_SetParameter(uint8_t param, uint32_t value) {
  uint8_t UP3D_CMD_56_X_Y[6] = {0x56, param, 0x00, 0x00, 0x00, 0x00};
  memcpy(&UP3D_CMD_56_X_Y[2], &value, sizeof(value));
  uint8_t resp[2048];
  if ((UP3DCOMM_Write(UP3D_CMD_56_X_Y, sizeof(UP3D_CMD_56_X_Y)) !=
       sizeof(UP3D_CMD_56_X_Y)) ||
      (1 != UP3DCOMM_Read(resp, sizeof(resp))) || (6 != resp[0]))
    return false;
  return true;
}


x86 assembly (clang, -O0):
<UP3D_SetParameter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2030,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x56,-0x30(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x2c(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    -0x30(%rbp),%rdi
add    $0x8,%rdi
lea    -0xc(%rbp),%rsi
mov    $0x4,%edx
call   1050 <memcpy@plt>
lea    -0x30(%rbp),%rdi
mov    $0x18,%esi
call   1030 <UP3DCOMM_Write@plt>
cltq
cmp    $0x18,%rax
jne    11cb <UP3D_SetParameter+0x9b>
lea    -0x2030(%rbp),%rdi
mov    $0x2000,%esi
call   1040 <UP3DCOMM_Read@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%eax
jne    11cb <UP3D_SetParameter+0x9b>
mov    $0x6,%eax
cmp    -0x2030(%rbp),%eax
je     11d7 <UP3D_SetParameter+0xa7>
movl   $0x0,-0x4(%rbp)
jmp    11de <UP3D_SetParameter+0xae>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<UP3D_SetParameter>:
sub    $0x2038,%rsp
mov    %esi,0xc(%rsp)
movl   $0x56,0x10(%rsp)
mov    %edi,0x14(%rsp)
lea    0x18(%rsp),%rdi
xorps  %xmm0,%xmm0
movups %xmm0,0x18(%rsp)
lea    0xc(%rsp),%rsi
mov    $0x4,%edx
call   1050 <memcpy@plt>
lea    0x10(%rsp),%rdi
mov    $0x18,%esi
call   1030 <UP3DCOMM_Write@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x18,%ecx
jne    119d <UP3D_SetParameter+0x6d>
lea    0x30(%rsp),%rdi
mov    $0x2000,%esi
call   1040 <UP3DCOMM_Read@plt>
mov    %eax,%ecx
xor    $0x1,%ecx
mov    0x30(%rsp),%edx
xor    $0x6,%edx
xor    %eax,%eax
or     %ecx,%edx
sete   %al
add    $0x2038,%rsp
ret

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

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