#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*/ is_unicode(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int /*<<< orphan*/ strtol(char *, int /*<<< orphan*/ *, int);
wchar_t str2uni(char *p) {
  if (!is_unicode(p))
    return 0;
  char unicode[7];
  strncpy(unicode, p, 6);
  unicode[0] = '0';
  unicode[1] = 'x';
  unicode[6] = '\0';
  return (wchar_t)strtol(unicode, NULL, 16);
}


x86 assembly (clang, -O0):
<str2uni>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <is_unicode@plt>
cmp    $0x0,%eax
jne    115a <str2uni+0x2a>
movl   $0x0,-0x4(%rbp)
jmp    118d <str2uni+0x5d>
lea    -0x17(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x6,%edx
call   1030 <strncpy@plt>
movb   $0x30,-0x17(%rbp)
movb   $0x78,-0x16(%rbp)
movb   $0x0,-0x11(%rbp)
lea    -0x17(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1050 <strtol@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str2uni>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1040 <is_unicode@plt>
test   %eax,%eax
je     1172 <str2uni+0x42>
lea    0x1(%rsp),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x6,%edx
call   1030 <strncpy@plt>
movw   $0x7830,0x1(%rsp)
movb   $0x0,0x7(%rsp)
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <strtol@plt>
jmp    1174 <str2uni+0x44>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @str2uni(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [7 x i8]
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i32 @is_unicode(i8* %5)
%7 = icmp ne i32 %6, 0
br i1 %7, label %9, label %8
8: ; preds = %1
store i32 0, i32* %2
br label %18
9: ; preds = %1
%10 = getelementptr inbounds [7 x i8], [7 x i8]* %4, i64 0, i64 0
%11 = load i8*, i8** %3
%12 = call i32 @strncpy(i8* %10, i8* %11, i32 6)
%13 = getelementptr inbounds [7 x i8], [7 x i8]* %4, i64 0, i64 0
store i8 48, i8* %13
%14 = getelementptr inbounds [7 x i8], [7 x i8]* %4, i64 0, i64 1
store i8 120, i8* %14
%15 = getelementptr inbounds [7 x i8], [7 x i8]* %4, i64 0, i64 6
store i8 0, i8* %15
%16 = getelementptr inbounds [7 x i8], [7 x i8]* %4, i64 0, i64 0
%17 = call i32 @strtol(i8* %16, i32* null, i32 16)
store i32 %17, i32* %2
br label %18
18: ; preds = %9, %8
%19 = load i32, i32* %2
ret i32 %19
}

LLVM IR (-O2):
define i32 @str2uni(i8* %0) {
%2 = alloca [7 x i8]
%3 = tail call i32 @is_unicode(i8* %0)
%4 = icmp eq i32 %3, 0
br i1 %4, label %11, label %5
5: ; preds = %1
%6 = getelementptr inbounds [7 x i8], [7 x i8]* %2, i64 0, i64 0
%7 = call i32 @strncpy(i8* %6, i8* %0, i32 6)
store i8 48, i8* %6
%8 = getelementptr inbounds [7 x i8], [7 x i8]* %2, i64 0, i64 1
store i8 120, i8* %8
%9 = getelementptr inbounds [7 x i8], [7 x i8]* %2, i64 0, i64 6
store i8 0, i8* %9
%10 = call i32 @strtol(i8* nocapture %6, i32* null, i32 16)
br label %11
11: ; preds = %1, %5
%12 = phi i32 [ %10, %5 ], [ 0, %1 ]
ret i32 %12
}