#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 */

/* Variables and functions */
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strcat(char *, char *);
char *usb_debug_data(char *str, const char *data, int len) {
  char tmpstr[10];
  int i;
  str[0] = 0;
  for (i = 0; i < (len < 10 ? len : 10); i++) {
    sprintf(tmpstr, " 0x%02x", ((int)data[i]) & 0xff);
    if (i % 16 == 0 && i != 0)
      strcat(str, "\n");
    strcat(str, tmpstr);
  }
  if (i < len)
    strcat(str, " ...");
  return str;
}


x86 assembly (clang, -O0):
<usb_debug_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    115c <usb_debug_data+0x3c>
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    1169 <usb_debug_data+0x49>
mov    $0xa,%eax
mov    %eax,-0x2c(%rbp)
jmp    1169 <usb_debug_data+0x49>
mov    -0x28(%rbp),%eax
mov    -0x2c(%rbp),%ecx
cmp    %ecx,%eax
jge    11e2 <usb_debug_data+0xc2>
lea    -0x1e(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
and    $0xff,%edx
lea    0xe6c(%rip),%rsi
call   1040 <sprintf@plt>
mov    -0x24(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11c7 <usb_debug_data+0xa7>
cmpl   $0x0,-0x24(%rbp)
je     11c7 <usb_debug_data+0xa7>
mov    -0x8(%rbp),%rdi
lea    0xe46(%rip),%rsi
call   1030 <strcat@plt>
mov    -0x8(%rbp),%rdi
lea    -0x1e(%rbp),%rsi
call   1030 <strcat@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1141 <usb_debug_data+0x21>
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11fe <usb_debug_data+0xde>
mov    -0x8(%rbp),%rdi
lea    0xe11(%rip),%rsi
call   1030 <strcat@plt>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<usb_debug_data>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r12
movb   $0x0,(%rdi)
test   %edx,%edx
jle    11ae <usb_debug_data+0x8e>
mov    %rsi,%r13
cmp    $0xa,%edx
mov    $0xa,%ebp
mov    %edx,0x8(%rsp)
cmovb  %edx,%ebp
xor    %r14d,%r14d
lea    0xeac(%rip),%r15
lea    0xe(%rsp),%rbx
nopl   0x0(%rax)
movzbl 0x0(%r13,%r14,1),%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <sprintf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1030 <strcat@plt>
add    $0x1,%r14
cmp    %r14,%rbp
jne    1160 <usb_debug_data+0x40>
mov    0x8(%rsp),%edx
cmp    %edx,%ebp
jge    119c <usb_debug_data+0x7c>
lea    0xe74(%rip),%rsi
mov    %r12,%rdi
call   1030 <strcat@plt>
mov    %r12,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebp,%ebp
cmp    %edx,%ebp
jl     118d <usb_debug_data+0x6d>
jmp    119c <usb_debug_data+0x7c>

LLVM IR (-O0):
@.str = [8 x i8] c" 0x%02x\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [5 x i8] c" ...\00"
define i8* @usb_debug_data(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [10 x i8]
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i8*, i8** %4
%10 = getelementptr inbounds i8, i8* %9, i64 0
store i8 0, i8* %10
store i32 0, i32* %8
br label %11
11: ; preds = %44, %3
%12 = load i32, i32* %8
%13 = load i32, i32* %6
%14 = icmp slt i32 %13, 10
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = load i32, i32* %6
br label %18
17: ; preds = %11
br label %18
18: ; preds = %17, %15
%19 = phi i32 [ %16, %15 ], [ 10, %17 ]
%20 = icmp slt i32 %12, %19
br i1 %20, label %21, label %47
21: ; preds = %18
%22 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%23 = load i8*, i8** %5
%24 = load i32, i32* %8
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = and i32 %28, 255
%30 = call i32 @sprintf(i8* %22, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %29)
%31 = load i32, i32* %8
%32 = srem i32 %31, 16
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %40
34: ; preds = %21
%35 = load i32, i32* %8
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %34
%38 = load i8*, i8** %4
%39 = call i32 @strcat(i8* %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %40
40: ; preds = %37, %34, %21
%41 = load i8*, i8** %4
%42 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%43 = call i32 @strcat(i8* %41, i8* %42)
br label %44
44: ; preds = %40
%45 = load i32, i32* %8
%46 = add nsw i32 %45, 1
store i32 %46, i32* %8
br label %11
47: ; preds = %18
%48 = load i32, i32* %8
%49 = load i32, i32* %6
%50 = icmp slt i32 %48, %49
br i1 %50, label %51, label %54
51: ; preds = %47
%52 = load i8*, i8** %4
%53 = call i32 @strcat(i8* %52, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %54
54: ; preds = %51, %47
%55 = load i8*, i8** %4
ret i8* %55
}

LLVM IR (-O2):
@.str = [8 x i8] c" 0x%02x\00"
@.str.2 = [5 x i8] c" ...\00"
define i8* @usb_debug_data(i8* returned %0, i8* nocapture %1, i32 %2) {
%4 = alloca [10 x i8]
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
store i8 0, i8* %0
%6 = icmp sgt i32 %2, 0
br i1 %6, label %7, label %20
7: ; preds = %3
%8 = icmp ult i32 %2, 10
%9 = select i1 %8, i32 %2, i32 10
%10 = zext i32 %9 to i64
br label %11
11: ; preds = %11, %7
%12 = phi i64 [ 0, %7 ], [ %18, %11 ]
%13 = getelementptr inbounds i8, i8* %1, i64 %12
%14 = load i8, i8* %13
%15 = zext i8 %14 to i32
%16 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = call i32 @strcat(i8* %0, i8* %5)
%18 = add nuw nsw i64 %12, 1
%19 = icmp eq i64 %18, %10
br i1 %19, label %20, label %11
20: ; preds = %11, %3
%21 = phi i32 [ 0, %3 ], [ %9, %11 ]
%22 = icmp slt i32 %21, %2
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = call i32 @strcat(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %23, %20
ret i8* %0
}