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

/* Variables and functions */
int UP3DCOMM_Read(int *, int);
int UP3DCOMM_Write(int const *, int);
bool UP3D_ClearProgramBuf() {
  static const uint8_t UP3D_CMD_43[] = {0x43};
  uint8_t resp[2048];
  if ((UP3DCOMM_Write(UP3D_CMD_43, sizeof(UP3D_CMD_43)) !=
       sizeof(UP3D_CMD_43)) ||
      (1 != UP3DCOMM_Read(resp, sizeof(resp))) || (6 != resp[0]))
    return false;
  return true;
}


x86 assembly (clang, -O0):
<UP3D_ClearProgramBuf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2010,%rsp
lea    0xece(%rip),%rdi
mov    $0x4,%esi
call   1030 <UP3DCOMM_Write@plt>
cltq
cmp    $0x4,%rax
jne    1179 <UP3D_ClearProgramBuf+0x59>
lea    -0x2010(%rbp),%rdi
mov    $0x2000,%esi
call   1040 <UP3DCOMM_Read@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%eax
jne    1179 <UP3D_ClearProgramBuf+0x59>
mov    $0x6,%eax
cmp    -0x2010(%rbp),%eax
je     1185 <UP3D_ClearProgramBuf+0x65>
movl   $0x0,-0x4(%rbp)
jmp    118c <UP3D_ClearProgramBuf+0x6c>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2010,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<UP3D_ClearProgramBuf>:
sub    $0x2008,%rsp
lea    0xed2(%rip),%rdi
mov    $0x4,%esi
call   1030 <UP3DCOMM_Write@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x4,%ecx
jne    1160 <UP3D_ClearProgramBuf+0x40>
mov    %rsp,%rdi
mov    $0x2000,%esi
call   1040 <UP3DCOMM_Read@plt>
mov    %eax,%ecx
xor    $0x1,%ecx
mov    (%rsp),%edx
xor    $0x6,%edx
xor    %eax,%eax
or     %ecx,%edx
sete   %al
add    $0x2008,%rsp
ret

LLVM IR (-O0):
@UP3D_ClearProgramBuf.UP3D_CMD_43 = internal constant [1 x i32] [i32 67]
define i32 @UP3D_ClearProgramBuf() {
%1 = alloca i32
%2 = alloca [2048 x i32]
%3 = call i32 @UP3DCOMM_Write(i32* getelementptr inbounds ([1 x i32], [1 x i32]* @UP3D_ClearProgramBuf.UP3D_CMD_43, 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 1, %8
br i1 %9, label %14, label %10
10: ; preds = %6
%11 = getelementptr inbounds [2048 x i32], [2048 x i32]* %2, i64 0, i64 0
%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 %16
15: ; preds = %10
store i32 1, i32* %1
br label %16
16: ; preds = %15, %14
%17 = load i32, i32* %1
ret i32 %17
}

LLVM IR (-O2):
@UP3D_ClearProgramBuf.UP3D_CMD_43 = internal constant [1 x i32] [i32 67]
define i32 @UP3D_ClearProgramBuf() {
%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_ClearProgramBuf.UP3D_CMD_43, i64 0, i64 0), i32 4)
%4 = icmp eq i32 %3, 4
br i1 %4, label %5, label %13
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 eq i32 %7, 1
%9 = load i32, i32* %6
%10 = icmp eq i32 %9, 6
%11 = select i1 %8, i1 %10, i1 false
%12 = zext i1 %11 to i32
br label %13
13: ; preds = %5, %0
%14 = phi i32 [ 0, %0 ], [ %12, %5 ]
ret i32 %14
}