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

/* Variables and functions */
scalar_t__ *malloc(size_t);
size_t strlen(char const *);
wchar_t *mkwide(const char *in) {
  size_t len = strlen(in);
  wchar_t *out = malloc((len + 1) * sizeof(wchar_t));
  wchar_t *q;
  const unsigned char *s = (const unsigned char *)in;
  for (q = out; *s;)
    *q++ = *s++;
  *q = 0;
  return out;
}


x86 assembly (clang, -O0):
<mkwide>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
shl    $0x3,%rdi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
cmpb   $0x0,(%rax)
je     1196 <mkwide+0x76>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movzbl (%rax),%eax
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x8,%rdx
mov    %rdx,-0x20(%rbp)
mov    %rcx,(%rax)
jmp    115e <mkwide+0x3e>
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mkwide>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
lea    0x8(,%rax,8),%rdi
call   1040 <malloc@plt>
mov    (%rbx),%cl
mov    %rax,%rdx
test   %cl,%cl
je     1165 <mkwide+0x45>
add    $0x1,%rbx
mov    %rax,%rdx
cs nopw 0x0(%rax,%rax,1)
movzbl %cl,%ecx
mov    %rcx,(%rdx)
add    $0x8,%rdx
movzbl (%rbx),%ecx
add    $0x1,%rbx
test   %cl,%cl
jne    1150 <mkwide+0x30>
movq   $0x0,(%rdx)
pop    %rbx
ret

LLVM IR (-O0):
define i64* @mkwide(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i64*
%5 = alloca i64*
%6 = alloca i8*
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i64 @strlen(i8* %7)
store i64 %8, i64* %3
%9 = load i64, i64* %3
%10 = add i64 %9, 1
%11 = mul i64 %10, 8
%12 = call i64* @malloc(i64 %11)
store i64* %12, i64** %4
%13 = load i8*, i8** %2
store i8* %13, i8** %6
%14 = load i64*, i64** %4
store i64* %14, i64** %5
br label %15
15: ; preds = %19, %1
%16 = load i8*, i8** %6
%17 = load i8, i8* %16
%18 = icmp ne i8 %17, 0
br i1 %18, label %19, label %26
19: ; preds = %15
%20 = load i8*, i8** %6
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %6
%22 = load i8, i8* %20
%23 = zext i8 %22 to i64
%24 = load i64*, i64** %5
%25 = getelementptr inbounds i64, i64* %24, i32 1
store i64* %25, i64** %5
store i64 %23, i64* %24
br label %15
26: ; preds = %15
%27 = load i64*, i64** %5
store i64 0, i64* %27
%28 = load i64*, i64** %4
ret i64* %28
}

LLVM IR (-O2):
define noalias i64* @mkwide(i8* nocapture %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = shl i64 %2, 3
%4 = add i64 %3, 8
%5 = tail call i64* @malloc(i64 %4)
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %17, label %8
8: ; preds = %1, %8
%9 = phi i8 [ %15, %8 ], [ %6, %1 ]
%10 = phi i8* [ %12, %8 ], [ %0, %1 ]
%11 = phi i64* [ %14, %8 ], [ %5, %1 ]
%12 = getelementptr inbounds i8, i8* %10, i64 1
%13 = zext i8 %9 to i64
%14 = getelementptr inbounds i64, i64* %11, i64 1
store i64 %13, i64* %11
%15 = load i8, i8* %12
%16 = icmp eq i8 %15, 0
br i1 %16, label %17, label %8
17: ; preds = %8, %1
%18 = phi i64* [ %5, %1 ], [ %14, %8 ]
store i64 0, i64* %18
ret i64* %5
}