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

/* Variables and functions */
int strlen(char const *);
scalar_t__ unicode_from_utf8(char const **, char const *, unsigned int *);
unsigned int UnicodeFromUtf8(const char **src) {
  unsigned int ret = 0;
  const char *end = *src + strlen(*src);
  if (end == *src)
    return 0;
  if (unicode_from_utf8(src, end, &ret) == 0)
    return ret;
  return 0;
}


x86 assembly (clang, -O0):
<UnicodeFromUtf8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%rax
jne    1177 <UnicodeFromUtf8+0x57>
movl   $0x0,-0x4(%rbp)
jmp    11a4 <UnicodeFromUtf8+0x84>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   1040 <unicode_from_utf8@plt>
cmp    $0x0,%rax
jne    119d <UnicodeFromUtf8+0x7d>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a4 <UnicodeFromUtf8+0x84>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<UnicodeFromUtf8>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
movl   $0x0,0x4(%rsp)
mov    (%rdi),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
movslq %eax,%rsi
add    %rbx,%rsi
cmp    (%r14),%rsi
je     1162 <UnicodeFromUtf8+0x42>
lea    0x4(%rsp),%rdx
mov    %r14,%rdi
call   1040 <unicode_from_utf8@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    1164 <UnicodeFromUtf8+0x44>
mov    0x4(%rsp),%eax
jmp    1164 <UnicodeFromUtf8+0x44>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i32 @UnicodeFromUtf8(i8** %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%4 = load i8*, i8** %0
%5 = tail call i32 @strlen(i8* %4)
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds i8, i8* %4, i64 %6
%8 = load i8*, i8** %0
%9 = icmp eq i8* %7, %8
br i1 %9, label %15, label %10
10: ; preds = %1
%11 = call i64 @unicode_from_utf8(i8** %0, i8* %7, i32* %2)
%12 = icmp eq i64 %11, 0
%13 = load i32, i32* %2
%14 = select i1 %12, i32 %13, i32 0
br label %15
15: ; preds = %10, %1
%16 = phi i32 [ 0, %1 ], [ %14, %10 ]
ret i32 %16
}