#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 convert_string(char *, char *, char const *, char **, char);
char *malloc(int);
int utf8_decode(const char *from, char **to) {
  char *charset;
  if (*from == 0) {
    *to = malloc(1);
    **to = 0;
    return 1;
  }
  return convert_string("UTF-8", "US-ASCII", from, to, '?');
}


x86 assembly (clang, -O0):
<utf8_decode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    116a <utf8_decode+0x4a>
mov    $0x1,%edi
call   1040 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movb   $0x0,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    118e <utf8_decode+0x6e>
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe87(%rip),%rdi
lea    0xe86(%rip),%rsi
mov    $0x3f,%r8d
call   1030 <convert_string@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<utf8_decode>:
push   %rbx
mov    %rsi,%rbx
cmpb   $0x0,(%rdi)
je     1149 <utf8_decode+0x29>
mov    %rdi,%rdx
lea    0xecd(%rip),%rdi
lea    0xecc(%rip),%rsi
mov    %rbx,%rcx
mov    $0x3f,%r8d
pop    %rbx
jmp    1030 <convert_string@plt>
mov    $0x1,%edi
call   1040 <malloc@plt>
mov    %rax,(%rbx)
movb   $0x0,(%rax)
mov    $0x1,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [6 x i8] c"UTF-8\00"
@.str.1 = [9 x i8] c"US-ASCII\00"
define i32 @utf8_decode(i8* %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i8*
store i8* %0, i8** %4
store i8** %1, i8*** %5
%7 = load i8*, i8** %4
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = call i8* @malloc(i32 1)
%13 = load i8**, i8*** %5
store i8* %12, i8** %13
%14 = load i8**, i8*** %5
%15 = load i8*, i8** %14
store i8 0, i8* %15
store i32 1, i32* %3
br label %20
16: ; preds = %2
%17 = load i8*, i8** %4
%18 = load i8**, i8*** %5
%19 = call i32 @convert_string(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %17, i8** %18, i8 signext 63)
store i32 %19, i32* %3
br label %20
20: ; preds = %16, %11
%21 = load i32, i32* %3
ret i32 %21
}

LLVM IR (-O2):
@.str = [6 x i8] c"UTF-8\00"
@.str.1 = [9 x i8] c"US-ASCII\00"
define i32 @utf8_decode(i8* %0, i8** %1) {
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call dereferenceable_or_null(1) i8* @malloc(i32 1)
store i8* %6, i8** %1
store i8 0, i8* %6
br label %9
7: ; preds = %2
%8 = tail call i32 @convert_string(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8** %1, i8 signext 63)
br label %9
9: ; preds = %7, %5
%10 = phi i32 [ 1, %5 ], [ %8, %7 ]
ret i32 %10
}