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

/* Variables and functions */
int /*<<< orphan*/ *malloc(int);
int wcslen(int /*<<< orphan*/ const *);
wchar_t *strdup_wchar(const wchar_t *src) {
  int len = wcslen(src);
  wchar_t *tmp, *dst;
  if (!(dst = malloc((len + 1) * sizeof(wchar_t))))
    return NULL;
  tmp = dst;
  while ((*dst++ = *src++))
    ;
  return tmp;
}


x86 assembly (clang, -O0):
<strdup_wchar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <wcslen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1166 <strdup_wchar+0x46>
movq   $0x0,-0x8(%rbp)
jmp    11a6 <strdup_wchar+0x86>
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%eax
mov    -0x28(%rbp),%rcx
mov    %rcx,%rdx
add    $0x4,%rdx
mov    %rdx,-0x28(%rbp)
mov    %eax,(%rcx)
cmp    $0x0,%eax
je     119e <strdup_wchar+0x7e>
jmp    116e <strdup_wchar+0x4e>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strdup_wchar>:
push   %rbx
mov    %rdi,%rbx
call   1030 <wcslen@plt>
lea    0x4(,%rax,4),%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     114e <strdup_wchar+0x2e>
xor    %ecx,%ecx
nopl   0x0(%rax)
mov    (%rbx,%rcx,1),%edx
mov    %edx,(%rax,%rcx,1)
add    $0x4,%rcx
test   %edx,%edx
jne    1140 <strdup_wchar+0x20>
pop    %rbx
ret

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

LLVM IR (-O2):
define noalias i32* @strdup_wchar(i32* nocapture %0) {
%2 = tail call i32 @wcslen(i32* %0)
%3 = shl i32 %2, 2
%4 = add i32 %3, 4
%5 = tail call i32* @malloc(i32 %4)
%6 = icmp eq i32* %5, null
br i1 %6, label %14, label %7
7: ; preds = %1, %7
%8 = phi i32* [ %10, %7 ], [ %0, %1 ]
%9 = phi i32* [ %12, %7 ], [ %5, %1 ]
%10 = getelementptr inbounds i32, i32* %8, i64 1
%11 = load i32, i32* %8
%12 = getelementptr inbounds i32, i32* %9, i64 1
store i32 %11, i32* %9
%13 = icmp eq i32 %11, 0
br i1 %13, label %14, label %7
14: ; preds = %7, %1
ret i32* %5
}