#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*/ uint8_t;
typedef int /*<<< orphan*/ abBuf;

/* Variables and functions */
int doctrl(int, int, int /*<<< orphan*/, int /*<<< orphan*/, int,
           int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ hex(int /*<<< orphan*/ *, int, char *);
int /*<<< orphan*/ memset(int /*<<< orphan*/ *, int /*<<< orphan*/, int);
int recv_bulk(int, int /*<<< orphan*/ *, int);
void palm(void) {
  uint8_t abVendor[0x14] = {0};
  int cb = doctrl(0x80 | (0x2 << (5)) | 0x2, 0x04, 0, 0, 0x14, abVendor,
                  "vendor req");
  hex(abVendor, cb, "palm vendor req");
  uint8_t abBuf[512];
  memset(abBuf, 0, sizeof(abBuf));
  cb = recv_bulk(6, abBuf, 6);
  hex(abBuf, cb, "bulk 1");
  memset(abBuf, 0, sizeof(abBuf));
  cb = recv_bulk(6, abBuf, 22);
  hex(abBuf, cb, "bulk 2");
}


x86 assembly (clang, -O0):
<palm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x870,%rsp
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1030 <memset@plt>
lea    -0x50(%rbp),%r9
mov    $0xc2,%edi
mov    $0x4,%esi
xor    %ecx,%ecx
mov    $0x14,%r8d
lea    0xe8d(%rip),%rax
mov    %ecx,%edx
mov    %rax,(%rsp)
call   1040 <doctrl@plt>
mov    %eax,-0x54(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x54(%rbp),%esi
lea    0xe6c(%rip),%rdx
call   1060 <hex@plt>
lea    -0x860(%rbp),%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1030 <memset@plt>
lea    -0x860(%rbp),%rsi
mov    $0x6,%edx
mov    %edx,%edi
call   1050 <recv_bulk@plt>
mov    %eax,-0x54(%rbp)
lea    -0x860(%rbp),%rdi
mov    -0x54(%rbp),%esi
lea    0xe3d(%rip),%rdx
call   1060 <hex@plt>
lea    -0x860(%rbp),%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1030 <memset@plt>
lea    -0x860(%rbp),%rsi
mov    $0x6,%edi
mov    $0x16,%edx
call   1050 <recv_bulk@plt>
mov    %eax,-0x54(%rbp)
lea    -0x860(%rbp),%rdi
mov    -0x54(%rbp),%esi
lea    0xe02(%rip),%rdx
call   1060 <hex@plt>
add    $0x870,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<palm>:
push   %rbx
sub    $0x860,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
lea    0xe9a(%rip),%rax
mov    %rax,(%rsp)
lea    0x10(%rsp),%rbx
mov    $0xc2,%edi
mov    $0x4,%esi
xor    %edx,%edx
xor    %ecx,%ecx
mov    $0x14,%r8d
mov    %rbx,%r9
call   1040 <doctrl@plt>
lea    0xe69(%rip),%rdx
mov    %rbx,%rdi
mov    %eax,%esi
call   1060 <hex@plt>
lea    0x60(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1030 <memset@plt>
mov    $0x6,%edi
mov    %rbx,%rsi
mov    $0x6,%edx
call   1050 <recv_bulk@plt>
lea    0xe42(%rip),%rdx
mov    %rbx,%rdi
mov    %eax,%esi
call   1060 <hex@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1030 <memset@plt>
mov    $0x6,%edi
mov    %rbx,%rsi
mov    $0x16,%edx
call   1050 <recv_bulk@plt>
lea    0xe17(%rip),%rdx
mov    %rbx,%rdi
mov    %eax,%esi
call   1060 <hex@plt>
add    $0x860,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [11 x i8] c"vendor req\00"
@.str.1 = [16 x i8] c"palm vendor req\00"
@.str.2 = [7 x i8] c"bulk 1\00"
@.str.3 = [7 x i8] c"bulk 2\00"
define void @palm() {
%1 = alloca [20 x i32]
%2 = alloca i32
%3 = alloca [512 x i32]
%4 = bitcast [20 x i32]* %1 to i8*
%5 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 0
%6 = call i32 @doctrl(i32 194, i32 4, i32 0, i32 0, i32 20, i32* %5, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i32 %6, i32* %2
%7 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 0
%8 = load i32, i32* %2
%9 = call i32 @hex(i32* %7, i32 %8, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%10 = getelementptr inbounds [512 x i32], [512 x i32]* %3, i64 0, i64 0
%11 = call i32 @memset(i32* %10, i32 0, i32 2048)
%12 = getelementptr inbounds [512 x i32], [512 x i32]* %3, i64 0, i64 0
%13 = call i32 @recv_bulk(i32 6, i32* %12, i32 6)
store i32 %13, i32* %2
%14 = getelementptr inbounds [512 x i32], [512 x i32]* %3, i64 0, i64 0
%15 = load i32, i32* %2
%16 = call i32 @hex(i32* %14, i32 %15, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%17 = getelementptr inbounds [512 x i32], [512 x i32]* %3, i64 0, i64 0
%18 = call i32 @memset(i32* %17, i32 0, i32 2048)
%19 = getelementptr inbounds [512 x i32], [512 x i32]* %3, i64 0, i64 0
%20 = call i32 @recv_bulk(i32 6, i32* %19, i32 22)
store i32 %20, i32* %2
%21 = getelementptr inbounds [512 x i32], [512 x i32]* %3, i64 0, i64 0
%22 = load i32, i32* %2
%23 = call i32 @hex(i32* %21, i32 %22, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"vendor req\00"
@.str.1 = [16 x i8] c"palm vendor req\00"
@.str.2 = [7 x i8] c"bulk 1\00"
@.str.3 = [7 x i8] c"bulk 2\00"
define void @palm() {
%1 = alloca [20 x i32]
%2 = alloca [512 x i32]
%3 = bitcast [20 x i32]* %1 to i8*
%4 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 0
%5 = call i32 @doctrl(i32 194, i32 4, i32 0, i32 0, i32 20, i32* %4, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @hex(i32* %4, i32 %5, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%7 = bitcast [512 x i32]* %2 to i8*
%8 = getelementptr inbounds [512 x i32], [512 x i32]* %2, i64 0, i64 0
%9 = call i32 @memset(i32* %8, i32 0, i32 2048)
%10 = call i32 @recv_bulk(i32 6, i32* %8, i32 6)
%11 = call i32 @hex(i32* %8, i32 %10, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 @memset(i32* %8, i32 0, i32 2048)
%13 = call i32 @recv_bulk(i32 6, i32* %8, i32 22)
%14 = call i32 @hex(i32* %8, i32 %13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
ret void
}