#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 */
int /*<<< orphan*/ free(scalar_t__ *);
scalar_t__ malloc(int);
scalar_t__ mbtowc(scalar_t__ *, char const *, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char const *);
int gbcode_get_character_unicode_int(const char *str) {
  if (str == NULL)
    return -1;
  wchar_t *h = (wchar_t *)malloc(sizeof(wchar_t));
  if (mbtowc(h, str, strlen(str)) < 0)
    return -1;
  int ret = (int)h[0];
  free(h);
  return ret;
}


x86 assembly (clang, -O0):
<gbcode_get_character_unicode_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1163 <gbcode_get_character_unicode_int+0x23>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c8 <gbcode_get_character_unicode_int+0x88>
mov    $0x8,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1050 <mbtowc@plt>
cmp    $0x0,%rax
jge    11af <gbcode_get_character_unicode_int+0x6f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c8 <gbcode_get_character_unicode_int+0x88>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gbcode_get_character_unicode_int>:
push   %rbp
push   %r14
push   %rbx
mov    $0xffffffff,%r14d
test   %rdi,%rdi
je     1184 <gbcode_get_character_unicode_int+0x44>
mov    %rdi,%rbp
mov    $0x8,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1050 <mbtowc@plt>
test   %rax,%rax
js     1184 <gbcode_get_character_unicode_int+0x44>
mov    (%rbx),%r14d
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @gbcode_get_character_unicode_int(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %13, label %3
3: ; preds = %1
%4 = tail call i64 @malloc(i32 8)
%5 = inttoptr i64 %4 to i64*
%6 = tail call i32 @strlen(i8* %0)
%7 = tail call i64 @mbtowc(i64* %5, i8* %0, i32 %6)
%8 = icmp slt i64 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %3
%10 = load i64, i64* %5
%11 = trunc i64 %10 to i32
%12 = tail call i32 @free(i64* %5)
br label %13
13: ; preds = %9, %3, %1
%14 = phi i32 [ -1, %1 ], [ %11, %9 ], [ -1, %3 ]
ret i32 %14
}