#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 */
struct ttrie__obj {
  int dummy;
};
typedef int ssize_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int parse_key_value(char *, int, unsigned char **, int **);
int ttrie__get(struct ttrie__obj *, unsigned char *, int, unsigned long long *);
int check_expected(char *expected_path, struct ttrie__obj *ttp) {
  char *line = NULL;
  size_t len = 0;
  ssize_t read;
  unsigned char *key;
  int *val;
  int num_checks = 0;
  FILE *fp_expected = fopen(expected_path, "r");
  if (fp_expected == NULL)
    exit(EXIT_FAILURE);
  while ((read = getline(&line, &len, fp_expected)) != -1) {
    int key_size = parse_key_value(line, read, &key, &val);
    unsigned long long result;
    int rc = ttrie__get(ttp, key, key_size, &result);
    assert(rc == 0);
    assert(result == *val);
    num_checks += 1;
  }
  fclose(fp_expected);
  free(line);
  return num_checks;
}


x86 assembly (clang, -O0):
<check_expected>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe4e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    11d4 <check_expected+0x54>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
jmp    11d9 <check_expected+0x59>
mov    -0x48(%rbp),%rdx
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1090 <getline@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
je     125e <check_expected+0xde>
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%esi
lea    -0x30(%rbp),%rdx
lea    -0x38(%rbp),%rcx
call   1080 <parse_key_value@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x4c(%rbp),%edx
lea    -0x58(%rbp),%rcx
call   1040 <ttrie__get@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x58(%rbp),%rax
mov    -0x38(%rbp),%rcx
movslq (%rcx),%rcx
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11d9 <check_expected+0x59>
mov    -0x48(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x3c(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_expected>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
movq   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
lea    0xe57(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1264 <check_expected+0xe4>
mov    %rax,%rbx
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
mov    %rax,%rdx
call   1090 <getline@plt>
xor    %ebp,%ebp
cmp    $0xffffffff,%eax
je     1242 <check_expected+0xc2>
lea    0x10(%rsp),%r13
mov    %rsp,%r15
lea    0x8(%rsp),%r12
xchg   %ax,%ax
mov    (%rsp),%rdi
mov    %eax,%esi
lea    0x20(%rsp),%rdx
lea    0x18(%rsp),%rcx
call   1080 <parse_key_value@plt>
mov    0x20(%rsp),%rsi
mov    %r14,%rdi
mov    %eax,%edx
mov    %r13,%rcx
call   1040 <ttrie__get@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1060 <assert@plt>
mov    0x18(%rsp),%rax
movslq (%rax),%rax
xor    %edi,%edi
cmp    %rax,0x10(%rsp)
sete   %dil
call   1060 <assert@plt>
add    $0x1,%ebp
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1090 <getline@plt>
cmp    $0xffffffff,%eax
jne    11e0 <check_expected+0x60>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d75(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.ttrie__obj = type { i32 }
@.str = [2 x i8] c"r\00"
@EXIT_FAILURE = global i32 0
define i32 @check_expected(i8* %0, %struct.ttrie__obj* %1) {
%3 = alloca i8*
%4 = alloca %struct.ttrie__obj*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i64
%14 = alloca i32
store i8* %0, i8** %3
store %struct.ttrie__obj* %1, %struct.ttrie__obj** %4
store i8* null, i8** %5
store i64 0, i64* %6
store i32 0, i32* %10
%15 = load i8*, i8** %3
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %11
%17 = load i32*, i32** %11
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %22
19: ; preds = %2
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %2
br label %23
23: ; preds = %27, %22
%24 = load i32*, i32** %11
%25 = call i32 @getline(i8** %5, i64* %6, i32* %24)
store i32 %25, i32* %7
%26 = icmp ne i32 %25, -1
br i1 %26, label %27, label %48
27: ; preds = %23
%28 = load i8*, i8** %5
%29 = load i32, i32* %7
%30 = call i32 @parse_key_value(i8* %28, i32 %29, i8** %8, i32** %9)
store i32 %30, i32* %12
%31 = load %struct.ttrie__obj*, %struct.ttrie__obj** %4
%32 = load i8*, i8** %8
%33 = load i32, i32* %12
%34 = call i32 @ttrie__get(%struct.ttrie__obj* %31, i8* %32, i32 %33, i64* %13)
store i32 %34, i32* %14
%35 = load i32, i32* %14
%36 = icmp eq i32 %35, 0
%37 = zext i1 %36 to i32
%38 = call i32 @assert(i32 %37)
%39 = load i64, i64* %13
%40 = load i32*, i32** %9
%41 = load i32, i32* %40
%42 = sext i32 %41 to i64
%43 = icmp eq i64 %39, %42
%44 = zext i1 %43 to i32
%45 = call i32 @assert(i32 %44)
%46 = load i32, i32* %10
%47 = add nsw i32 %46, 1
store i32 %47, i32* %10
br label %23
48: ; preds = %23
%49 = load i32*, i32** %11
%50 = call i32 @fclose(i32* %49)
%51 = load i8*, i8** %5
%52 = call i32 @free(i8* %51)
%53 = load i32, i32* %10
ret i32 %53
}

LLVM IR (-O2):
%struct.ttrie__obj = type { i32 }
@.str = [2 x i8] c"r\00"
@EXIT_FAILURE = global i32 0
define i32 @check_expected(i8* nocapture %0, %struct.ttrie__obj* %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i64
%8 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%9 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%10 = bitcast i8** %5 to i8*
%11 = bitcast i32** %6 to i8*
%12 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %19, label %14
14: ; preds = %2
%15 = call i32 @getline(i8** %3, i64* %4, i32* %12)
%16 = icmp eq i32 %15, -1
br i1 %16, label %42, label %17
17: ; preds = %14
%18 = bitcast i64* %7 to i8*
br label %22
19: ; preds = %2
%20 = load i32, i32* @EXIT_FAILURE
%21 = tail call i32 @exit(i32 %20)
unreachable
22: ; preds = %17, %22
%23 = phi i32 [ %15, %17 ], [ %40, %22 ]
%24 = phi i32 [ 0, %17 ], [ %39, %22 ]
%25 = load i8*, i8** %3
%26 = call i32 @parse_key_value(i8* %25, i32 %23, i8** %5, i32** %6)
%27 = load i8*, i8** %5
%28 = call i32 @ttrie__get(%struct.ttrie__obj* %1, i8* %27, i32 %26, i64* %7)
%29 = icmp eq i32 %28, 0
%30 = zext i1 %29 to i32
%31 = call i32 @assert(i32 %30)
%32 = load i64, i64* %7
%33 = load i32*, i32** %6
%34 = load i32, i32* %33
%35 = sext i32 %34 to i64
%36 = icmp eq i64 %32, %35
%37 = zext i1 %36 to i32
%38 = call i32 @assert(i32 %37)
%39 = add nuw nsw i32 %24, 1
%40 = call i32 @getline(i8** %3, i64* %4, i32* %12)
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %22
42: ; preds = %22, %14
%43 = phi i32 [ 0, %14 ], [ %39, %22 ]
%44 = call i32 @fclose(i32* %12)
%45 = load i8*, i8** %3
%46 = call i32 @free(i8* %45)
ret i32 %43
}