#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*/ set_interface(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ usleep(int);
void msd() {
  unsigned InEndPt = 1;
  unsigned OutEndPt = 1;
  unsigned char abBuf[512];
  int i;
  set_interface(0, 0);
  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)
xor    %esi,%esi
mov    %esi,%edi
call   1070 <set_interface@plt>
movl   $0x0,-0x214(%rbp)
cmpl   $0x3,-0x214(%rbp)
jge    1308 <msd+0x188>
mov    -0x214(%rbp),%esi
lea    0xe3a(%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    0xe1a(%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    0xdd5(%rip),%rdx
call   1090 <hex@plt>
mov    -0x8(%rbp),%edi
lea    -0x210(%rbp),%rsi
mov    $0x1f,%edx
call   1050 <send_bulk@plt>
cmp    $0x0,%rax
jge    125e <msd+0xde>
jmp    1308 <msd+0x188>
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   1080 <recv_bulk@plt>
mov    %eax,-0x218(%rbp)
lea    -0x210(%rbp),%rdi
mov    -0x218(%rbp),%esi
lea    0xd79(%rip),%rdx
call   1090 <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   1080 <recv_bulk@plt>
mov    %eax,-0x218(%rbp)
lea    -0x210(%rbp),%rdi
mov    -0x218(%rbp),%esi
lea    0xd42(%rip),%rdx
call   1090 <hex@plt>
mov    $0x249f0,%edi
call   10a0 <usleep@plt>
mov    -0x214(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x214(%rbp)
jmp    11ac <msd+0x2c>
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
xor    %edi,%edi
xor    %esi,%esi
call   1070 <set_interface@plt>
mov    %rsp,%r15
lea    0xe60(%rip),%r12
lea    0xe5e(%rip),%r13
lea    0xe64(%rip),%rbp
lea    0xe6c(%rip),%r14
nopl   0x0(%rax,%rax,1)
lea    0xe39(%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   1090 <hex@plt>
mov    $0x1,%edi
mov    %r15,%rsi
mov    $0x1f,%edx
call   1050 <send_bulk@plt>
test   %rax,%rax
js     12a4 <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   1080 <recv_bulk@plt>
mov    %r15,%rdi
mov    %eax,%esi
mov    %rbp,%rdx
call   1090 <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   1080 <recv_bulk@plt>
mov    %r15,%rdi
mov    %eax,%esi
mov    %r14,%rdx
call   1090 <hex@plt>
mov    $0x249f0,%edi
call   10a0 <usleep@plt>
add    $0x1,%ebx
cmp    $0x3,%ebx
jne    11c0 <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
%6 = call i32 @set_interface(i32 0, i32 0)
store i32 0, i32* %4
br label %7
7: ; preds = %49, %0
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 3
br i1 %9, label %10, label %52
10: ; preds = %7
%11 = load i32, i32* %4
%12 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%14 = call i32 @memset(i8* %13, i32 0, i32 512)
%15 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%16 = call i32 @memcpy(i8* %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%17 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 4
%18 = bitcast i8* %17 to i32*
store i32 305334660, i32* %18
%19 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 8
store i8 36, i8* %19
%20 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 12
store i8 -128, i8* %20
%21 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 14
store i8 6, i8* %21
%22 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 15
store i8 18, i8* %22
%23 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 19
store i8 36, i8* %23
%24 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%25 = call i32 @hex(i8* %24, i32 31, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%26 = load i32, i32* %2
%27 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%28 = call i64 @send_bulk(i32 %26, i8* %27, i32 31)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %10
br label %52
31: ; preds = %10
%32 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%33 = call i32 @memset(i8* %32, i32 0, i32 512)
%34 = load i32, i32* %1
%35 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%36 = call i32 @recv_bulk(i32 %34, i8* %35, i32 36)
store i32 %36, i32* %5
%37 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%38 = load i32, i32* %5
%39 = call i32 @hex(i8* %37, i32 %38, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%40 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%41 = call i32 @memset(i8* %40, i32 0, i32 512)
%42 = load i32, i32* %1
%43 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%44 = call i32 @recv_bulk(i32 %42, i8* %43, i32 36)
store i32 %44, i32* %5
%45 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%46 = load i32, i32* %5
%47 = call i32 @hex(i8* %45, i32 %46, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%48 = call i32 @usleep(i32 150000)
br label %49
49: ; preds = %31
%50 = load i32, i32* %4
%51 = add nsw i32 %50, 1
store i32 %51, i32* %4
br label %7
52: ; preds = %30, %7
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 = tail call i32 @set_interface(i32 0, i32 0)
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 4
%5 = bitcast i8* %4 to i32*
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 8
%7 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 12
%8 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 14
%9 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 15
%10 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 19
br label %11
11: ; preds = %0, %19
%12 = phi i32 [ 0, %0 ], [ %27, %19 ]
%13 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = call i32 @memset(i8* %2, i32 0, i32 512)
%15 = 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* %5
store i8 36, i8* %6
store i8 -128, i8* %7
store i8 6, i8* %8
store i8 18, i8* %9
store i8 36, i8* %10
%16 = call i32 @hex(i8* %2, i32 31, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%17 = call i64 @send_bulk(i32 1, i8* %2, i32 31)
%18 = icmp slt i64 %17, 0
br i1 %18, label %29, label %19
19: ; preds = %11
%20 = call i32 @memset(i8* %2, i32 0, i32 512)
%21 = call i32 @recv_bulk(i32 1, i8* %2, i32 36)
%22 = call i32 @hex(i8* %2, i32 %21, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%23 = call i32 @memset(i8* %2, i32 0, i32 512)
%24 = call i32 @recv_bulk(i32 1, i8* %2, i32 36)
%25 = call i32 @hex(i8* %2, i32 %24, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%26 = call i32 @usleep(i32 150000)
%27 = add nuw nsw i32 %12, 1
%28 = icmp eq i32 %27, 3
br i1 %28, label %29, label %11
29: ; preds = %19, %11
ret void
}