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

/* Variables and functions */
int UP3DCOMM_Read(int *, int);
int UP3DCOMM_Write(int *, int);
bool UP3D_SendRandom() {
  uint8_t UP3D_CMD_2B_RRR[9] = {0x2B, 0xCA, 0xFE, 0x00, 0x00,
                                0x00, 0x00, 0x12, 0x34};
  uint8_t resp[2048];
  if ((UP3DCOMM_Write(UP3D_CMD_2B_RRR, sizeof(UP3D_CMD_2B_RRR)) !=
       sizeof(UP3D_CMD_2B_RRR)) ||
      (1 != UP3DCOMM_Read(resp, sizeof(resp))) || (6 != resp[0]))
    return false;
  return true;
}


x86 assembly (clang, -O0):
<UP3D_SendRandom>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2030,%rsp
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x24,%edx
call   1050 <memset@plt>
movl   $0x2b,-0x30(%rbp)
movl   $0xca,-0x2c(%rbp)
movl   $0xfe,-0x28(%rbp)
movl   $0x12,-0x14(%rbp)
movl   $0x34,-0x10(%rbp)
lea    -0x30(%rbp),%rdi
mov    $0x24,%esi
call   1030 <UP3DCOMM_Write@plt>
cltq
cmp    $0x24,%rax
jne    11b9 <UP3D_SendRandom+0x89>
lea    -0x2030(%rbp),%rdi
mov    $0x2000,%esi
call   1040 <UP3DCOMM_Read@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%eax
jne    11b9 <UP3D_SendRandom+0x89>
mov    $0x6,%eax
cmp    -0x2030(%rbp),%eax
je     11c5 <UP3D_SendRandom+0x95>
movl   $0x0,-0x4(%rbp)
jmp    11cc <UP3D_SendRandom+0x9c>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<UP3D_SendRandom>:
sub    $0x2038,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movaps %xmm0,0x10(%rsp)
movabs $0xca0000002b,%rax
mov    %rax,(%rsp)
movl   $0xfe,0x8(%rsp)
movl   $0x12,0x1c(%rsp)
movl   $0x34,0x20(%rsp)
mov    %rsp,%rdi
mov    $0x24,%esi
call   1030 <UP3DCOMM_Write@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x24,%ecx
jne    1191 <UP3D_SendRandom+0x71>
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_SendRandom() {
%1 = alloca i32
%2 = alloca [9 x i32]
%3 = alloca [2048 x i32]
%4 = bitcast [9 x i32]* %2 to i8*
%5 = bitcast i8* %4 to [9 x i32]*
%6 = getelementptr inbounds [9 x i32], [9 x i32]* %5, i32 0, i32 0
store i32 43, i32* %6
%7 = getelementptr inbounds [9 x i32], [9 x i32]* %5, i32 0, i32 1
store i32 202, i32* %7
%8 = getelementptr inbounds [9 x i32], [9 x i32]* %5, i32 0, i32 2
store i32 254, i32* %8
%9 = getelementptr inbounds [9 x i32], [9 x i32]* %5, i32 0, i32 7
store i32 18, i32* %9
%10 = getelementptr inbounds [9 x i32], [9 x i32]* %5, i32 0, i32 8
store i32 52, i32* %10
%11 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 0
%12 = call i32 @UP3DCOMM_Write(i32* %11, i32 36)
%13 = sext i32 %12 to i64
%14 = icmp ne i64 %13, 36
br i1 %14, label %23, label %15
15: ; preds = %0
%16 = getelementptr inbounds [2048 x i32], [2048 x i32]* %3, i64 0, i64 0
%17 = call i32 @UP3DCOMM_Read(i32* %16, i32 8192)
%18 = icmp ne i32 1, %17
br i1 %18, label %23, label %19
19: ; preds = %15
%20 = getelementptr inbounds [2048 x i32], [2048 x i32]* %3, i64 0, i64 0
%21 = load i32, i32* %20
%22 = icmp ne i32 6, %21
br i1 %22, label %23, label %24
23: ; preds = %19, %15, %0
store i32 0, i32* %1
br label %25
24: ; preds = %19
store i32 1, i32* %1
br label %25
25: ; preds = %24, %23
%26 = load i32, i32* %1
ret i32 %26
}

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