#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 strlen(char *);
int /*<<< orphan*/ willus_mem_alloc_warn(void **, int, char *, int);
short *char_to_wide(short *d, char *s) {
  static char *funcname = "char_to_wide";
  unsigned short *x;
  unsigned char *p;
  int i;
  if (d == NULL)
    willus_mem_alloc_warn((void **)&x, sizeof(short) * (strlen(s) + 1),
                          funcname, 10);
  else
    x = (unsigned short *)d;
  p = (unsigned char *)s;
  for (i = 0; p[i] != '\0'; i++)
    x[i] = p[i];
  x[i] = 0;
  return ((short *)x);
}


x86 assembly (clang, -O0):
<char_to_wide>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1171 <char_to_wide+0x51>
lea    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rdi
add    $0x1,%eax
cltq
shl    $0x1,%rax
mov    %eax,%esi
mov    0x2ece(%rip),%rdx
mov    $0xa,%ecx
call   1030 <willus_mem_alloc_warn@plt>
jmp    1179 <char_to_wide+0x59>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11c6 <char_to_wide+0xa6>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    %ax,%dx
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %dx,(%rax,%rcx,2)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1188 <char_to_wide+0x68>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movw   $0x0,(%rax,%rcx,2)
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<char_to_wide>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
test   %rdi,%rdi
je     1134 <char_to_wide+0x14>
mov    %rdi,0x8(%rsp)
jmp    1158 <char_to_wide+0x38>
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    (%rax,%rax,1),%esi
add    $0x2,%esi
lea    0xeb7(%rip),%rdx
lea    0x8(%rsp),%rdi
mov    $0xa,%ecx
call   1030 <willus_mem_alloc_warn@plt>
mov    (%rbx),%dl
mov    0x8(%rsp),%rax
xor    %ecx,%ecx
test   %dl,%dl
je     1186 <char_to_wide+0x66>
cs nopw 0x0(%rax,%rax,1)
nop
movzbl %dl,%edx
mov    %dx,(%rax,%rcx,2)
movzbl 0x1(%rbx,%rcx,1),%edx
add    $0x1,%rcx
test   %dl,%dl
jne    1170 <char_to_wide+0x50>
mov    %ecx,%ecx
movw   $0x0,(%rax,%rcx,2)
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [13 x i8] c"char_to_wide\00"
define i16* @char_to_wide(i16* %0, i8* %1) {
%3 = alloca i16*
%4 = bitcast i16** %3 to i8*
%5 = icmp eq i16* %0, null
br i1 %5, label %6, label %12
6: ; preds = %2
%7 = bitcast i16** %3 to i8**
%8 = tail call i32 @strlen(i8* %1)
%9 = shl i32 %8, 1
%10 = add i32 %9, 2
%11 = call i32 @willus_mem_alloc_warn(i8** %7, i32 %10, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 10)
br label %13
12: ; preds = %2
store i16* %0, i16** %3
br label %13
13: ; preds = %12, %6
%14 = load i8, i8* %1
%15 = icmp eq i8 %14, 0
%16 = load i16*, i16** %3
br i1 %15, label %28, label %17
17: ; preds = %13, %17
%18 = phi i64 [ %22, %17 ], [ 0, %13 ]
%19 = phi i8 [ %24, %17 ], [ %14, %13 ]
%20 = zext i8 %19 to i16
%21 = getelementptr inbounds i16, i16* %16, i64 %18
store i16 %20, i16* %21
%22 = add nuw nsw i64 %18, 1
%23 = getelementptr inbounds i8, i8* %1, i64 %22
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 0
br i1 %25, label %26, label %17
26: ; preds = %17
%27 = and i64 %22, 4294967295
br label %28
28: ; preds = %13, %26
%29 = phi i64 [ %27, %26 ], [ 0, %13 ]
%30 = getelementptr inbounds i16, i16* %16, i64 %29
store i16 0, i16* %30
ret i16* %16
}