#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*/ UFILE;
typedef int /*<<< orphan*/ UChar;

/* Variables and functions */
int /*<<< orphan*/ free(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, long);
int /*<<< orphan*/ *read_utf8_file(char *, long *);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ u_fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *u_finit(int /*<<< orphan*/, int /*<<< orphan*/ *,
                            int /*<<< orphan*/ *);
int /*<<< orphan*/ u_fprintf(int /*<<< orphan*/ *, char *,
                             int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  UFILE *u_stdout;
  long size;
  UChar *str = read_utf8_file("utf8_test.txt", &size);
  printf("String size: %ld\n\n", size);
  u_stdout = u_finit(stdout, NULL, NULL);
  u_fprintf(u_stdout, "%S\n", str);
  u_fclose(u_stdout);
  free(str);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe83(%rip),%rdi
lea    -0x20(%rbp),%rsi
call   1080 <read_utf8_file@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe79(%rip),%rdi
call   1050 <printf@plt>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   1040 <u_finit@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xe5f(%rip),%rsi
call   1060 <u_fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1070 <u_fclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xe95(%rip),%rdi
mov    %rsp,%rsi
call   1080 <read_utf8_file@plt>
mov    %rax,%r14
mov    (%rsp),%rsi
lea    0xe8d(%rip),%rdi
call   1050 <printf@plt>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <u_finit@plt>
mov    %rax,%rbx
lea    0xe7f(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
call   1060 <u_fprintf@plt>
mov    %rbx,%rdi
call   1070 <u_fclose@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [14 x i8] c"utf8_test.txt\00"
@.str.1 = [19 x i8] c"String size: %ld\0A\0A\00"
@stdout = global i32 0
@.str.2 = [4 x i8] c"%S\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32* @read_utf8_file(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i64* %7)
store i32* %9, i32** %8
%10 = load i64, i64* %7
%11 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i64 %10)
%12 = load i32, i32* @stdout
%13 = call i32* @u_finit(i32 %12, i32* null, i32* null)
store i32* %13, i32** %6
%14 = load i32*, i32** %6
%15 = load i32*, i32** %8
%16 = call i32 @u_fprintf(i32* %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32* %15)
%17 = load i32*, i32** %6
%18 = call i32 @u_fclose(i32* %17)
%19 = load i32*, i32** %8
%20 = call i32 @free(i32* %19)
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"utf8_test.txt\00"
@.str.1 = [19 x i8] c"String size: %ld\0A\0A\00"
@stdout = global i32 0
@.str.2 = [4 x i8] c"%S\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to i8*
%5 = call i32* @read_utf8_file(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i64* %3)
%6 = load i64, i64* %3
%7 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i64 %6)
%8 = load i32, i32* @stdout
%9 = call i32* @u_finit(i32 %8, i32* null, i32* null)
%10 = call i32 @u_fprintf(i32* %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32* %5)
%11 = call i32 @u_fclose(i32* %9)
%12 = call i32 @free(i32* %5)
ret i32 0
}