#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 */
unsigned long long *calloc(int, int);
int /*<<< orphan*/ utf_char_to_code(char *, unsigned long long *, int *);
void string_to_codes(char *str, int length, unsigned long long **ret_codes,
                     int *ret_length) {
  unsigned int code;
  char byte_length;
  *ret_codes = calloc(length, sizeof(long long));
  *ret_length = 0;
  for (int i = 0; i < length;) {
    int byte_length;
    utf_char_to_code(&str[i], &(*ret_codes)[*ret_length], &byte_length);
    *ret_length += 1;
    i += byte_length;
  }
}


x86 assembly (clang, -O0):
<string_to_codes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0xc(%rbp),%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11ad <string_to_codes+0x8d>
mov    -0x8(%rbp),%rdi
movslq -0x2c(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
mov    -0x20(%rbp),%rax
movslq (%rax),%rax
shl    $0x3,%rax
add    %rax,%rsi
lea    -0x30(%rbp),%rdx
call   1040 <utf_char_to_code@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x30(%rbp),%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    115f <string_to_codes+0x3f>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_to_codes>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%rbx
mov    %rdx,%r14
mov    %esi,%r13d
mov    %rdi,%r15
mov    %esi,%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,(%r14)
movl   $0x0,(%rbx)
test   %r13d,%r13d
jle    11a9 <string_to_codes+0x89>
lea    0x4(%rsp),%rdx
mov    %r15,%rdi
mov    %rax,%rsi
call   1040 <utf_char_to_code@plt>
mov    (%rbx),%eax
add    $0x1,%eax
mov    %eax,(%rbx)
mov    0x4(%rsp),%ebp
cmp    %r13d,%ebp
jge    11a9 <string_to_codes+0x89>
lea    0x4(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
movslq %eax,%rsi
shl    $0x3,%rsi
add    (%r14),%rsi
movslq %ebp,%rbp
lea    (%r15,%rbp,1),%rdi
mov    %r12,%rdx
call   1040 <utf_char_to_code@plt>
mov    (%rbx),%eax
add    $0x1,%eax
mov    %eax,(%rbx)
add    0x4(%rsp),%ebp
cmp    %r13d,%ebp
jl     1180 <string_to_codes+0x60>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @string_to_codes(i8* %0, i32 %1, i64** %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i64**
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i8
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i64** %2, i64*** %7
store i32* %3, i32** %8
%13 = load i32, i32* %6
%14 = call i64* @calloc(i32 %13, i32 8)
%15 = load i64**, i64*** %7
store i64* %14, i64** %15
%16 = load i32*, i32** %8
store i32 0, i32* %16
store i32 0, i32* %11
br label %17
17: ; preds = %21, %4
%18 = load i32, i32* %11
%19 = load i32, i32* %6
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %39
21: ; preds = %17
%22 = load i8*, i8** %5
%23 = load i32, i32* %11
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i64**, i64*** %7
%27 = load i64*, i64** %26
%28 = load i32*, i32** %8
%29 = load i32, i32* %28
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i64, i64* %27, i64 %30
%32 = call i32 @utf_char_to_code(i8* %25, i64* %31, i32* %12)
%33 = load i32*, i32** %8
%34 = load i32, i32* %33
%35 = add nsw i32 %34, 1
store i32 %35, i32* %33
%36 = load i32, i32* %12
%37 = load i32, i32* %11
%38 = add nsw i32 %37, %36
store i32 %38, i32* %11
br label %17
39: ; preds = %17
ret void
}

LLVM IR (-O2):
define void @string_to_codes(i8* %0, i32 %1, i64** nocapture %2, i32* nocapture %3) {
%5 = alloca i32
%6 = tail call i64* @calloc(i32 %1, i32 8)
store i64* %6, i64** %2
store i32 0, i32* %3
%7 = icmp sgt i32 %1, 0
br i1 %7, label %8, label %15
8: ; preds = %4
%9 = bitcast i32* %5 to i8*
%10 = call i32 @utf_char_to_code(i8* %0, i64* %6, i32* %5)
%11 = load i32, i32* %3
%12 = add nsw i32 %11, 1
store i32 %12, i32* %3
%13 = load i32, i32* %5
%14 = icmp slt i32 %13, %1
br i1 %14, label %16, label %15
15: ; preds = %16, %8, %4
ret void
16: ; preds = %8, %16
%17 = phi i32 [ %28, %16 ], [ %13, %8 ]
%18 = phi i32 [ %26, %16 ], [ %12, %8 ]
%19 = load i64*, i64** %2
%20 = sext i32 %17 to i64
%21 = getelementptr inbounds i8, i8* %0, i64 %20
%22 = sext i32 %18 to i64
%23 = getelementptr inbounds i64, i64* %19, i64 %22
%24 = call i32 @utf_char_to_code(i8* %21, i64* %23, i32* %5)
%25 = load i32, i32* %3
%26 = add nsw i32 %25, 1
store i32 %26, i32* %3
%27 = load i32, i32* %5
%28 = add nsw i32 %27, %17
%29 = icmp slt i32 %28, %1
br i1 %29, label %16, label %15
}