#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 USBD_GetLen(unsigned char *);
void USBD_GetString(unsigned char *desc, unsigned char *unicode,
                    unsigned short *len) {
  unsigned char idx = 0;
  if (desc != 0) {
    *len = USBD_GetLen(desc) * 2 + 2;
    unicode[idx++] = *len;
    unicode[idx++] = 3;
    while (*desc != 0) {
      unicode[idx++] = *desc++;
      unicode[idx++] = 0x00;
    }
  }
}


x86 assembly (clang, -O0):
<USBD_GetString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movb   $0x0,-0x19(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11dc <USBD_GetString+0xcc>
mov    -0x8(%rbp),%rdi
call   1030 <USBD_GetLen@plt>
shl    $0x1,%eax
add    $0x2,%eax
mov    %ax,%cx
mov    -0x18(%rbp),%rax
mov    %cx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%ax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x19(%rbp),%cl
mov    %cl,%sil
add    $0x1,%sil
mov    %sil,-0x19(%rbp)
movzbl %cl,%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    -0x19(%rbp),%cl
mov    %cl,%dl
add    $0x1,%dl
mov    %dl,-0x19(%rbp)
movzbl %cl,%ecx
movb   $0x3,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x0,%eax
je     11d7 <USBD_GetString+0xc7>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%dl
mov    -0x10(%rbp),%rax
mov    -0x19(%rbp),%cl
mov    %cl,%sil
add    $0x1,%sil
mov    %sil,-0x19(%rbp)
movzbl %cl,%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    -0x19(%rbp),%cl
mov    %cl,%dl
add    $0x1,%dl
mov    %dl,-0x19(%rbp)
movzbl %cl,%ecx
movb   $0x0,(%rax,%rcx,1)
jmp    1183 <USBD_GetString+0x73>
jmp    11dc <USBD_GetString+0xcc>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<USBD_GetString>:
push   %r15
push   %r14
push   %rbx
test   %rdi,%rdi
je     1172 <USBD_GetString+0x62>
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <USBD_GetLen@plt>
add    %eax,%eax
add    $0x2,%eax
mov    %ax,(%r15)
mov    %al,(%r14)
movb   $0x3,0x1(%r14)
mov    (%rbx),%al
test   %al,%al
je     1172 <USBD_GetString+0x62>
add    $0x1,%rbx
mov    $0x2,%cl
cs nopw 0x0(%rax,%rax,1)
nop
movzbl %cl,%edx
add    $0x1,%cl
mov    %al,(%r14,%rdx,1)
add    $0x2,%dl
movzbl %cl,%eax
movb   $0x0,(%r14,%rax,1)
movzbl (%rbx),%eax
add    $0x1,%rbx
mov    %edx,%ecx
test   %al,%al
jne    1150 <USBD_GetString+0x40>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @USBD_GetString(i8* %0, i8* %1, i16* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i16*
%7 = alloca i8
store i8* %0, i8** %4
store i8* %1, i8** %5
store i16* %2, i16** %6
store i8 0, i8* %7
%8 = load i8*, i8** %4
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %50
10: ; preds = %3
%11 = load i8*, i8** %4
%12 = call i32 @USBD_GetLen(i8* %11)
%13 = mul nsw i32 %12, 2
%14 = add nsw i32 %13, 2
%15 = trunc i32 %14 to i16
%16 = load i16*, i16** %6
store i16 %15, i16* %16
%17 = load i16*, i16** %6
%18 = load i16, i16* %17
%19 = trunc i16 %18 to i8
%20 = load i8*, i8** %5
%21 = load i8, i8* %7
%22 = add i8 %21, 1
store i8 %22, i8* %7
%23 = zext i8 %21 to i64
%24 = getelementptr inbounds i8, i8* %20, i64 %23
store i8 %19, i8* %24
%25 = load i8*, i8** %5
%26 = load i8, i8* %7
%27 = add i8 %26, 1
store i8 %27, i8* %7
%28 = zext i8 %26 to i64
%29 = getelementptr inbounds i8, i8* %25, i64 %28
store i8 3, i8* %29
br label %30
30: ; preds = %35, %10
%31 = load i8*, i8** %4
%32 = load i8, i8* %31
%33 = zext i8 %32 to i32
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %49
35: ; preds = %30
%36 = load i8*, i8** %4
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %4
%38 = load i8, i8* %36
%39 = load i8*, i8** %5
%40 = load i8, i8* %7
%41 = add i8 %40, 1
store i8 %41, i8* %7
%42 = zext i8 %40 to i64
%43 = getelementptr inbounds i8, i8* %39, i64 %42
store i8 %38, i8* %43
%44 = load i8*, i8** %5
%45 = load i8, i8* %7
%46 = add i8 %45, 1
store i8 %46, i8* %7
%47 = zext i8 %45 to i64
%48 = getelementptr inbounds i8, i8* %44, i64 %47
store i8 0, i8* %48
br label %30
49: ; preds = %30
br label %50
50: ; preds = %49, %3
ret void
}

LLVM IR (-O2):
define void @USBD_GetString(i8* %0, i8* nocapture writeonly %1, i16* nocapture writeonly %2) {
%4 = icmp eq i8* %0, null
br i1 %4, label %27, label %5
5: ; preds = %3
%6 = tail call i32 @USBD_GetLen(i8* %0)
%7 = trunc i32 %6 to i16
%8 = shl i16 %7, 1
%9 = add i16 %8, 2
store i16 %9, i16* %2
%10 = trunc i16 %9 to i8
store i8 %10, i8* %1
%11 = getelementptr inbounds i8, i8* %1, i64 1
store i8 3, i8* %11
%12 = load i8, i8* %0
%13 = icmp eq i8 %12, 0
br i1 %13, label %27, label %14
14: ; preds = %5, %14
%15 = phi i8 [ %25, %14 ], [ %12, %5 ]
%16 = phi i8 [ %22, %14 ], [ 2, %5 ]
%17 = phi i8* [ %18, %14 ], [ %0, %5 ]
%18 = getelementptr inbounds i8, i8* %17, i64 1
%19 = or i8 %16, 1
%20 = zext i8 %16 to i64
%21 = getelementptr inbounds i8, i8* %1, i64 %20
store i8 %15, i8* %21
%22 = add i8 %16, 2
%23 = zext i8 %19 to i64
%24 = getelementptr inbounds i8, i8* %1, i64 %23
store i8 0, i8* %24
%25 = load i8, i8* %18
%26 = icmp eq i8 %25, 0
br i1 %26, label %27, label %14
27: ; preds = %14, %5, %3
ret void
}