#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 *malloc(int);
int /*<<< orphan*/ memset(int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ utf8_dec_ex(int *, int, char const *);
int utf8_len(char const *);
int *utf8_dec(const char *s) {
  if (s == NULL)
    return NULL;
  int dl = utf8_len(s) + 1;
  int sz = sizeof(int) * dl;
  int *r = malloc(sz);
  if (r != NULL) {
    memset(r, 0, sz);
    utf8_dec_ex(r, dl, s);
  }
  return r;
}


x86 assembly (clang, -O0):
<utf8_dec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1164 <utf8_dec+0x24>
movq   $0x0,-0x8(%rbp)
jmp    11bb <utf8_dec+0x7b>
mov    -0x10(%rbp),%rdi
call   1040 <utf8_len@plt>
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11b3 <utf8_dec+0x73>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%edx
xor    %esi,%esi
call   1030 <memset@plt>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1060 <utf8_dec_ex@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<utf8_dec>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     118e <utf8_dec+0x4e>
mov    %rdi,%r14
call   1040 <utf8_len@plt>
mov    %eax,%r15d
lea    0x4(,%r15,4),%ebp
mov    %ebp,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     118e <utf8_dec+0x4e>
mov    %rax,%rbx
add    $0x1,%r15d
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1030 <memset@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %r14,%rdx
call   1060 <utf8_dec_ex@plt>
jmp    1190 <utf8_dec+0x50>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32* @utf8_dec(i8* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %10
9: ; preds = %1
store i32* null, i32** %2
br label %32
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = call i32 @utf8_len(i8* %11)
%13 = add nsw i32 %12, 1
store i32 %13, i32* %4
%14 = load i32, i32* %4
%15 = sext i32 %14 to i64
%16 = mul i64 4, %15
%17 = trunc i64 %16 to i32
store i32 %17, i32* %5
%18 = load i32, i32* %5
%19 = call i32* @malloc(i32 %18)
store i32* %19, i32** %6
%20 = load i32*, i32** %6
%21 = icmp ne i32* %20, null
br i1 %21, label %22, label %30
22: ; preds = %10
%23 = load i32*, i32** %6
%24 = load i32, i32* %5
%25 = call i32 @memset(i32* %23, i32 0, i32 %24)
%26 = load i32*, i32** %6
%27 = load i32, i32* %4
%28 = load i8*, i8** %3
%29 = call i32 @utf8_dec_ex(i32* %26, i32 %27, i8* %28)
br label %30
30: ; preds = %22, %10
%31 = load i32*, i32** %6
store i32* %31, i32** %2
br label %32
32: ; preds = %30, %9
%33 = load i32*, i32** %2
ret i32* %33
}

LLVM IR (-O2):
define i32* @utf8_dec(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %12, label %3
3: ; preds = %1
%4 = tail call i32 @utf8_len(i8* %0)
%5 = add nsw i32 %4, 1
%6 = shl i32 %5, 2
%7 = tail call i32* @malloc(i32 %6)
%8 = icmp eq i32* %7, null
br i1 %8, label %12, label %9
9: ; preds = %3
%10 = tail call i32 @memset(i32* %7, i32 0, i32 %6)
%11 = tail call i32 @utf8_dec_ex(i32* %7, i32 %5, i8* %0)
br label %12
12: ; preds = %3, %9, %1
%13 = phi i32* [ null, %1 ], [ %7, %9 ], [ null, %3 ]
ret i32* %13
}