#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;

/* Variables and functions */
int strlen(char *);
int ohci_roothub_strdscr(uint8_t *ptr, char *str) {
  uint8_t *p = ptr;
  *p++ = strlen(str) * 2 + 2;
  *p++ = 0x03;
  while (*str) {
    *p++ = *str++;
    *p++ = 0;
  }
  return (p - ptr);
}


x86 assembly (clang, -O0):
<ohci_roothub_strdscr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
shl    $0x1,%ecx
add    $0x2,%ecx
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x18(%rbp)
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x18(%rbp)
movl   $0x3,(%rax)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     11a9 <ohci_roothub_strdscr+0x99>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x18(%rbp)
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x18(%rbp)
movl   $0x0,(%rax)
jmp    115f <ohci_roothub_strdscr+0x4f>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
sar    $0x2,%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ohci_roothub_strdscr>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <strlen@plt>
add    %eax,%eax
add    $0x2,%eax
mov    %eax,(%r14)
movl   $0x3,0x4(%r14)
lea    0x8(%r14),%rax
mov    (%rbx),%cl
test   %cl,%cl
je     115b <ohci_roothub_strdscr+0x4b>
add    $0x1,%rbx
movsbl %cl,%ecx
mov    %ecx,(%rax)
movl   $0x0,0x4(%rax)
add    $0x8,%rax
movzbl (%rbx),%ecx
add    $0x1,%rbx
test   %cl,%cl
jne    1140 <ohci_roothub_strdscr+0x30>
sub    %r14,%rax
shr    $0x2,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @ohci_roothub_strdscr(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32*
store i32* %0, i32** %3
store i8* %1, i8** %4
%6 = load i32*, i32** %3
store i32* %6, i32** %5
%7 = load i8*, i8** %4
%8 = call i32 @strlen(i8* %7)
%9 = mul nsw i32 %8, 2
%10 = add nsw i32 %9, 2
%11 = load i32*, i32** %5
%12 = getelementptr inbounds i32, i32* %11, i32 1
store i32* %12, i32** %5
store i32 %10, i32* %11
%13 = load i32*, i32** %5
%14 = getelementptr inbounds i32, i32* %13, i32 1
store i32* %14, i32** %5
store i32 3, i32* %13
br label %15
15: ; preds = %19, %2
%16 = load i8*, i8** %4
%17 = load i8, i8* %16
%18 = icmp ne i8 %17, 0
br i1 %18, label %19, label %28
19: ; preds = %15
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %4
%22 = load i8, i8* %20
%23 = sext i8 %22 to i32
%24 = load i32*, i32** %5
%25 = getelementptr inbounds i32, i32* %24, i32 1
store i32* %25, i32** %5
store i32 %23, i32* %24
%26 = load i32*, i32** %5
%27 = getelementptr inbounds i32, i32* %26, i32 1
store i32* %27, i32** %5
store i32 0, i32* %26
br label %15
28: ; preds = %15
%29 = load i32*, i32** %5
%30 = load i32*, i32** %3
%31 = ptrtoint i32* %29 to i64
%32 = ptrtoint i32* %30 to i64
%33 = sub i64 %31, %32
%34 = sdiv exact i64 %33, 4
%35 = trunc i64 %34 to i32
ret i32 %35
}

LLVM IR (-O2):
define i32 @ohci_roothub_strdscr(i32* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = shl nsw i32 %3, 1
%5 = add nsw i32 %4, 2
%6 = getelementptr inbounds i32, i32* %0, i64 1
store i32 %5, i32* %0
store i32 3, i32* %6
%7 = getelementptr inbounds i32, i32* %0, i64 2
%8 = load i8, i8* %1
%9 = icmp eq i8 %8, 0
br i1 %9, label %21, label %10
10: ; preds = %2, %10
%11 = phi i8 [ %19, %10 ], [ %8, %2 ]
%12 = phi i32* [ %18, %10 ], [ %7, %2 ]
%13 = phi i32* [ %12, %10 ], [ %0, %2 ]
%14 = phi i8* [ %15, %10 ], [ %1, %2 ]
%15 = getelementptr inbounds i8, i8* %14, i64 1
%16 = sext i8 %11 to i32
%17 = getelementptr inbounds i32, i32* %13, i64 3
store i32 %16, i32* %12
store i32 0, i32* %17
%18 = getelementptr inbounds i32, i32* %12, i64 2
%19 = load i8, i8* %15
%20 = icmp eq i8 %19, 0
br i1 %20, label %21, label %10
21: ; preds = %10, %2
%22 = phi i32* [ %7, %2 ], [ %18, %10 ]
%23 = ptrtoint i32* %22 to i64
%24 = ptrtoint i32* %0 to i64
%25 = sub i64 %23, %24
%26 = lshr exact i64 %25, 2
%27 = trunc i64 %26 to i32
ret i32 %27
}