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

/* Variables and functions */
int /*<<< orphan*/ hex(unsigned char *, int, char *);
int /*<<< orphan*/ memcpy(unsigned char *, char *, int);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, int);
int recv_bulk(unsigned int, unsigned char *, int);
scalar_t__ send_bulk(unsigned int, unsigned char *, int);
int /*<<< orphan*/ usleep(int);
void msd() {
  unsigned InEndPt = 1;
  unsigned OutEndPt = 1;
  unsigned char abBuf[512];
  int i;
  for (i = 0; i < 3; i++) {
    printf("i=%d\n", i);
    memset(abBuf, 0, sizeof(abBuf));
    memcpy(abBuf, "USBC", 4);
    *(uint32_t *)(&abBuf[4]) = 0x12330984;
    abBuf[8] = 0x24;
    abBuf[0xc] = 0x80;
    abBuf[0xe] = 0x06;
    abBuf[0x0f] = 0x12;
    abBuf[0x13] = 0x24;
    hex(abBuf, 31, "intquery req");
    if (send_bulk(OutEndPt, abBuf, 31) < 0)
      return;
    memset(abBuf, 0, sizeof(abBuf));
    int cb = recv_bulk(InEndPt, abBuf, 36);
    hex(abBuf, cb, "inquiry result");
    memset(abBuf, 0, sizeof(abBuf));
    cb = recv_bulk(InEndPt, abBuf, 36);
    hex(abBuf, cb, "inquiry sense?");
    usleep(150000);
  }
}


x86 assembly (clang, -O0):
<msd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
movl   $0x0,-0x214(%rbp)
cmpl   $0x3,-0x214(%rbp)
jge    12ef <msd+0x17f>
mov    -0x214(%rbp),%esi
lea    0xe53(%rip),%rdi
call   1030 <printf@plt>
lea    -0x210(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1040 <memset@plt>
lea    -0x210(%rbp),%rdi
lea    0xe33(%rip),%rsi
mov    $0x4,%edx
call   1060 <memcpy@plt>
movl   $0x12330984,-0x20c(%rbp)
09 33 12
movb   $0x24,-0x208(%rbp)
movb   $0x80,-0x204(%rbp)
movb   $0x6,-0x202(%rbp)
movb   $0x12,-0x201(%rbp)
movb   $0x24,-0x1fd(%rbp)
lea    -0x210(%rbp),%rdi
mov    $0x1f,%esi
lea    0xdee(%rip),%rdx
call   1080 <hex@plt>
mov    -0x8(%rbp),%edi
lea    -0x210(%rbp),%rsi
mov    $0x1f,%edx
call   1050 <send_bulk@plt>
cmp    $0x0,%rax
jge    1245 <msd+0xd5>
jmp    12ef <msd+0x17f>
lea    -0x210(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1040 <memset@plt>
mov    -0x4(%rbp),%edi
lea    -0x210(%rbp),%rsi
mov    $0x24,%edx
call   1070 <recv_bulk@plt>
mov    %eax,-0x218(%rbp)
lea    -0x210(%rbp),%rdi
mov    -0x218(%rbp),%esi
lea    0xd92(%rip),%rdx
call   1080 <hex@plt>
lea    -0x210(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1040 <memset@plt>
mov    -0x4(%rbp),%edi
lea    -0x210(%rbp),%rsi
mov    $0x24,%edx
call   1070 <recv_bulk@plt>
mov    %eax,-0x218(%rbp)
lea    -0x210(%rbp),%rdi
mov    -0x218(%rbp),%esi
lea    0xd5b(%rip),%rdx
call   1080 <hex@plt>
mov    $0x249f0,%edi
call   1090 <usleep@plt>
mov    -0x214(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x214(%rbp)
jmp    1193 <msd+0x23>
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<msd>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x208,%rsp
xor    %ebx,%ebx
mov    %rsp,%r15
lea    0xe79(%rip),%r12
lea    0xe77(%rip),%r13
lea    0xe7d(%rip),%rbp
lea    0xe85(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0xe49(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1040 <memset@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x4,%edx
call   1060 <memcpy@plt>
movl   $0x12330984,0x4(%rsp)
12
movb   $0x24,0x8(%rsp)
movb   $0x80,0xc(%rsp)
movw   $0x1206,0xe(%rsp)
movb   $0x24,0x13(%rsp)
mov    %r15,%rdi
mov    $0x1f,%esi
mov    %r13,%rdx
call   1080 <hex@plt>
mov    $0x1,%edi
mov    %r15,%rsi
mov    $0x1f,%edx
call   1050 <send_bulk@plt>
test   %rax,%rax
js     1294 <msd+0x124>
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1040 <memset@plt>
mov    $0x1,%edi
mov    %r15,%rsi
mov    $0x24,%edx
call   1070 <recv_bulk@plt>
mov    %r15,%rdi
mov    %eax,%esi
mov    %rbp,%rdx
call   1080 <hex@plt>
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1040 <memset@plt>
mov    $0x1,%edi
mov    %r15,%rsi
mov    $0x24,%edx
call   1070 <recv_bulk@plt>
mov    %r15,%rdi
mov    %eax,%esi
mov    %r14,%rdx
call   1080 <hex@plt>
mov    $0x249f0,%edi
call   1090 <usleep@plt>
add    $0x1,%ebx
cmp    $0x3,%ebx
jne    11b0 <msd+0x40>
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"i=%d\0A\00"
@.str.1 = [5 x i8] c"USBC\00"
@.str.2 = [13 x i8] c"intquery req\00"
@.str.3 = [15 x i8] c"inquiry result\00"
@.str.4 = [15 x i8] c"inquiry sense?\00"
define void @msd() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [512 x i8]
%4 = alloca i32
%5 = alloca i32
store i32 1, i32* %1
store i32 1, i32* %2
store i32 0, i32* %4
br label %6
6: ; preds = %48, %0
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 3
br i1 %8, label %9, label %51
9: ; preds = %6
%10 = load i32, i32* %4
%11 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%13 = call i32 @memset(i8* %12, i32 0, i32 512)
%14 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%15 = call i32 @memcpy(i8* %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%16 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 4
%17 = bitcast i8* %16 to i32*
store i32 305334660, i32* %17
%18 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 8
store i8 36, i8* %18
%19 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 12
store i8 -128, i8* %19
%20 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 14
store i8 6, i8* %20
%21 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 15
store i8 18, i8* %21
%22 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 19
store i8 36, i8* %22
%23 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%24 = call i32 @hex(i8* %23, i32 31, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%25 = load i32, i32* %2
%26 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%27 = call i64 @send_bulk(i32 %25, i8* %26, i32 31)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %9
br label %51
30: ; preds = %9
%31 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%32 = call i32 @memset(i8* %31, i32 0, i32 512)
%33 = load i32, i32* %1
%34 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%35 = call i32 @recv_bulk(i32 %33, i8* %34, i32 36)
store i32 %35, i32* %5
%36 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%37 = load i32, i32* %5
%38 = call i32 @hex(i8* %36, i32 %37, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%39 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%40 = call i32 @memset(i8* %39, i32 0, i32 512)
%41 = load i32, i32* %1
%42 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%43 = call i32 @recv_bulk(i32 %41, i8* %42, i32 36)
store i32 %43, i32* %5
%44 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%45 = load i32, i32* %5
%46 = call i32 @hex(i8* %44, i32 %45, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%47 = call i32 @usleep(i32 150000)
br label %48
48: ; preds = %30
%49 = load i32, i32* %4
%50 = add nsw i32 %49, 1
store i32 %50, i32* %4
br label %6
51: ; preds = %29, %6
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"i=%d\0A\00"
@.str.1 = [5 x i8] c"USBC\00"
@.str.2 = [13 x i8] c"intquery req\00"
@.str.3 = [15 x i8] c"inquiry result\00"
@.str.4 = [15 x i8] c"inquiry sense?\00"
define void @msd() {
%1 = alloca [512 x i8]
%2 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 0
%3 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 4
%4 = bitcast i8* %3 to i32*
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 8
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 12
%7 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 14
%8 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 15
%9 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 19
br label %10
10: ; preds = %0, %18
%11 = phi i32 [ 0, %0 ], [ %26, %18 ]
%12 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = call i32 @memset(i8* %2, i32 0, i32 512)
%14 = call i32 @memcpy(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
store i32 305334660, i32* %4
store i8 36, i8* %5
store i8 -128, i8* %6
store i8 6, i8* %7
store i8 18, i8* %8
store i8 36, i8* %9
%15 = call i32 @hex(i8* %2, i32 31, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%16 = call i64 @send_bulk(i32 1, i8* %2, i32 31)
%17 = icmp slt i64 %16, 0
br i1 %17, label %28, label %18
18: ; preds = %10
%19 = call i32 @memset(i8* %2, i32 0, i32 512)
%20 = call i32 @recv_bulk(i32 1, i8* %2, i32 36)
%21 = call i32 @hex(i8* %2, i32 %20, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%22 = call i32 @memset(i8* %2, i32 0, i32 512)
%23 = call i32 @recv_bulk(i32 1, i8* %2, i32 36)
%24 = call i32 @hex(i8* %2, i32 %23, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%25 = call i32 @usleep(i32 150000)
%26 = add nuw nsw i32 %11, 1
%27 = icmp eq i32 %26, 3
br i1 %27, label %28, label %10
28: ; preds = %18, %10
ret void
}