#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 int /*<<< orphan*/ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ assert(char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ memcpy(char *, char *, size_t);
char *unicode_is_valid_code_point(int /*<<< orphan*/);
char *unicode_write_string_utf7(int /*<<< orphan*/ *, int, size_t *);
int unicode_write_utf7(uint32_t code_point, char *string) {
  assert(string);
  assert(unicode_is_valid_code_point(code_point));
  size_t data_length;
  char *data = unicode_write_string_utf7(&code_point, 1, &data_length);
  memcpy(string, data, data_length);
  free(data);
  return (int)data_length;
}


x86 assembly (clang, -O0):
<unicode_write_utf7>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <assert@plt>
mov    -0x4(%rbp),%edi
call   1070 <unicode_is_valid_code_point@plt>
mov    %rax,%rdi
call   1040 <assert@plt>
lea    -0x4(%rbp),%rdi
mov    $0x1,%esi
lea    -0x18(%rbp),%rdx
call   1050 <unicode_write_string_utf7@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1060 <memcpy@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unicode_write_utf7>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %edi,0xc(%rsp)
mov    %rsi,%rdi
call   1040 <assert@plt>
mov    %ebp,%edi
call   1070 <unicode_is_valid_code_point@plt>
mov    %rax,%rdi
call   1040 <assert@plt>
lea    0xc(%rsp),%rdi
lea    0x10(%rsp),%rdx
mov    $0x1,%esi
call   1050 <unicode_write_string_utf7@plt>
mov    %rax,%rbp
mov    0x10(%rsp),%rdx
mov    %rbx,%rdi
mov    %rax,%rsi
call   1060 <memcpy@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    0x10(%rsp),%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @unicode_write_utf7(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
store i32 %0, i32* %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
%8 = call i32 @assert(i8* %7)
%9 = load i32, i32* %3
%10 = call i8* @unicode_is_valid_code_point(i32 %9)
%11 = call i32 @assert(i8* %10)
%12 = call i8* @unicode_write_string_utf7(i32* %3, i32 1, i64* %5)
store i8* %12, i8** %6
%13 = load i8*, i8** %4
%14 = load i8*, i8** %6
%15 = load i64, i64* %5
%16 = call i32 @memcpy(i8* %13, i8* %14, i64 %15)
%17 = load i8*, i8** %6
%18 = call i32 @free(i8* %17)
%19 = load i64, i64* %5
%20 = trunc i64 %19 to i32
ret i32 %20
}

LLVM IR (-O2):
define i32 @unicode_write_utf7(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i64
store i32 %0, i32* %3
%5 = tail call i32 @assert(i8* %1)
%6 = tail call i8* @unicode_is_valid_code_point(i32 %0)
%7 = tail call i32 @assert(i8* %6)
%8 = bitcast i64* %4 to i8*
%9 = call i8* @unicode_write_string_utf7(i32* %3, i32 1, i64* %4)
%10 = load i64, i64* %4
%11 = call i32 @memcpy(i8* %1, i8* %9, i64 %10)
%12 = call i32 @free(i8* %9)
%13 = load i64, i64* %4
%14 = trunc i64 %13 to i32
ret i32 %14
}