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

/* Variables and functions */
int /*<<< orphan*/ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ get_uint32(int /*<<< orphan*/ *, int *, int *);
int get_utf8_string(FILE *fp, int *next_offset) {
  uint32_t len;
  unsigned char buf[1024];
  get_uint32(fp, next_offset, &len);
  if (len == 0xffffffff) {
    return 1;
  } else if (len >= 0x7fffffff) {
    return 0;
  }
  fread(buf, len, 1, fp);
  *next_offset = *next_offset + len;
  return 1;
}


x86 assembly (clang, -O0):
<get_utf8_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   1040 <get_uint32@plt>
cmpl   $0xffffffff,-0x1c(%rbp)
jne    115a <get_utf8_string+0x3a>
movl   $0x1,-0x4(%rbp)
jmp    11a6 <get_utf8_string+0x86>
cmpl   $0x7fffffff,-0x1c(%rbp)
jl     1173 <get_utf8_string+0x53>
movl   $0x0,-0x4(%rbp)
jmp    11a6 <get_utf8_string+0x86>
jmp    1178 <get_utf8_string+0x58>
lea    -0x420(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x10(%rbp),%rcx
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_utf8_string>:
push   %rbp
push   %r14
push   %rbx
sub    $0x410,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xc(%rsp),%rdx
call   1040 <get_uint32@plt>
mov    0xc(%rsp),%esi
cmp    $0xffffffff,%esi
je     1150 <get_utf8_string+0x30>
cmp    $0x7fffffff,%esi
jne    1157 <get_utf8_string+0x37>
xor    %ebp,%ebp
jmp    1175 <get_utf8_string+0x55>
mov    $0x1,%ebp
jmp    1175 <get_utf8_string+0x55>
lea    0x10(%rsp),%rdi
mov    $0x1,%ebp
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    0xc(%rsp),%eax
add    %eax,(%r14)
mov    %ebp,%eax
add    $0x410,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @get_utf8_string(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca [1024 x i8]
store i32* %0, i32** %4
store i32* %1, i32** %5
%8 = load i32*, i32** %4
%9 = load i32*, i32** %5
%10 = call i32 @get_uint32(i32* %8, i32* %9, i32* %6)
%11 = load i32, i32* %6
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 1, i32* %3
br label %29
14: ; preds = %2
%15 = load i32, i32* %6
%16 = icmp sge i32 %15, 2147483647
br i1 %16, label %17, label %18
17: ; preds = %14
store i32 0, i32* %3
br label %29
18: ; preds = %14
br label %19
19: ; preds = %18
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%21 = load i32, i32* %6
%22 = load i32*, i32** %4
%23 = call i32 @fread(i8* %20, i32 %21, i32 1, i32* %22)
%24 = load i32*, i32** %5
%25 = load i32, i32* %24
%26 = load i32, i32* %6
%27 = add nsw i32 %25, %26
%28 = load i32*, i32** %5
store i32 %27, i32* %28
store i32 1, i32* %3
br label %29
29: ; preds = %19, %17, %13
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
define i32 @get_utf8_string(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca [1024 x i8]
%5 = bitcast i32* %3 to i8*
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = call i32 @get_uint32(i32* %0, i32* %1, i32* %3)
%8 = load i32, i32* %3
switch i32 %8, label %10 [
i32 -1, label %15
i32 2147483647, label %9
]
9: ; preds = %2
br label %15
10: ; preds = %2
%11 = call i32 @fread(i8* %6, i32 %8, i32 1, i32* %0)
%12 = load i32, i32* %1
%13 = load i32, i32* %3
%14 = add nsw i32 %13, %12
store i32 %14, i32* %1
br label %15
15: ; preds = %2, %10, %9
%16 = phi i32 [ 0, %9 ], [ 1, %10 ], [ 1, %2 ]
ret i32 %16
}