#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ make_wide_string(int /*<<< orphan*/ *, char const *, size_t,
                                    int *);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ stderr;
int strlen(char const *);
wchar_t *alloc_wide_string(const char *s, int *r_is_unicode) {
  wchar_t *wstr = NULL;
  size_t len = s ? strlen(s) + 1 : 1;
  wstr = (wchar_t *)malloc(len * sizeof(wchar_t));
  if (!wstr) {
    fprintf(stderr, "alloc_wide_string: Can't allocate mem!\n");
    exit(EXIT_FAILURE);
  }
  (void)make_wide_string(wstr, s ? s : "", len, r_is_unicode);
  return wstr;
}


x86 assembly (clang, -O0):
<alloc_wide_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1187 <alloc_wide_string+0x37>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1194 <alloc_wide_string+0x44>
mov    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1194 <alloc_wide_string+0x44>
mov    -0x24(%rbp),%eax
cltq
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
shl    $0x2,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11dc <alloc_wide_string+0x8c>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
lea    0xe37(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11fc <alloc_wide_string+0xac>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    120c <alloc_wide_string+0xbc>
lea    0xe24(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    120c <alloc_wide_string+0xbc>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%rcx
call   1060 <make_wide_string@plt>
mov    -0x18(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<alloc_wide_string>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r12
test   %rdi,%rdi
je     1173 <alloc_wide_string+0x23>
mov    %r12,%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
movslq %eax,%r15
jmp    1179 <alloc_wide_string+0x29>
mov    $0x1,%r15d
lea    0x0(,%r15,4),%rdi
call   1050 <malloc@plt>
test   %rax,%rax
je     11b9 <alloc_wide_string+0x69>
mov    %rax,%rbx
test   %r12,%r12
lea    0xe8f(%rip),%rsi
cmovne %r12,%rsi
mov    %rax,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
call   1060 <make_wide_string@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
lea    0xe37(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [40 x i8] c"alloc_wide_string: Can't allocate mem!\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [1 x i8] zeroinitializer
define i32* @alloc_wide_string(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i64
store i8* %0, i8** %3
store i32* %1, i32** %4
store i32* null, i32** %5
%7 = load i8*, i8** %3
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i8*, i8** %3
%11 = call i32 @strlen(i8* %10)
%12 = add nsw i32 %11, 1
br label %14
13: ; preds = %2
br label %14
14: ; preds = %13, %9
%15 = phi i32 [ %12, %9 ], [ 1, %13 ]
%16 = sext i32 %15 to i64
store i64 %16, i64* %6
%17 = load i64, i64* %6
%18 = mul i64 %17, 4
%19 = call i64 @malloc(i64 %18)
%20 = inttoptr i64 %19 to i32*
store i32* %20, i32** %5
%21 = load i32*, i32** %5
%22 = icmp ne i32* %21, null
br i1 %22, label %28, label %23
23: ; preds = %14
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %14
%29 = load i32*, i32** %5
%30 = load i8*, i8** %3
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %34
32: ; preds = %28
%33 = load i8*, i8** %3
br label %35
34: ; preds = %28
br label %35
35: ; preds = %34, %32
%36 = phi i8* [ %33, %32 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), %34 ]
%37 = load i64, i64* %6
%38 = load i32*, i32** %4
%39 = call i32 @make_wide_string(i32* %29, i8* %36, i64 %37, i32* %38)
%40 = load i32*, i32** %5
ret i32* %40
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [40 x i8] c"alloc_wide_string: Can't allocate mem!\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [1 x i8] zeroinitializer
define i32* @alloc_wide_string(i8* %0, i32* %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = tail call i32 @strlen(i8* %0)
%6 = add nsw i32 %5, 1
%7 = sext i32 %6 to i64
br label %8
8: ; preds = %2, %4
%9 = phi i64 [ %7, %4 ], [ 1, %2 ]
%10 = shl nsw i64 %9, 2
%11 = tail call i64 @malloc(i64 %10)
%12 = inttoptr i64 %11 to i32*
%13 = icmp eq i64 %11, 0
br i1 %13, label %14, label %19
14: ; preds = %8
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = tail call i32 @exit(i32 %17)
unreachable
19: ; preds = %8
%20 = select i1 %3, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* %0
%21 = tail call i32 @make_wide_string(i32* %12, i8* %20, i64 %9, i32* %1)
ret i32* %12
}