#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*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ fread_err(void *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
void toasim_read_64(void *val, FILE *file) {
  char key[8];
  uint32_t len;
  key[4] = '\0';
  fread_err(key, 4, 1, file);
  fread_err(&len, 4, 1, file);
  if (len != 8) {
    fprintf(stderr,
            "Error reading key '%s' expected 64 bit value, got 32 bit value\n",
            key);
  }
  fread_err(val, len, 1, file);
}


x86 assembly (clang, -O0):
<toasim_read_64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movb   $0x0,-0x14(%rbp)
lea    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x4,%esi
mov    $0x1,%edx
call   1040 <fread_err@plt>
lea    -0x1c(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x4,%esi
mov    $0x1,%edx
call   1040 <fread_err@plt>
cmpl   $0x8,-0x1c(%rbp)
je     1185 <toasim_read_64+0x65>
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rdx
lea    0xe80(%rip),%rsi
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x10(%rbp),%rcx
mov    $0x1,%edx
call   1040 <fread_err@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<toasim_read_64>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
movb   $0x0,0x14(%rsp)
lea    0x10(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread_err@plt>
lea    0xc(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread_err@plt>
mov    $0x8,%esi
cmpl   $0x8,0xc(%rsp)
je     118a <toasim_read_64+0x6a>
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
lea    0xe84(%rip),%rsi
lea    0x10(%rsp),%rdx
call   1030 <fprintf@plt>
mov    0xc(%rsp),%esi
mov    %r14,%rdi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread_err@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [64 x i8] c"Error reading key '%s' expected 64 bit value, got 32 bit value\0A\00"
define void @toasim_read_64(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [8 x i8]
%6 = alloca i32
store i8* %0, i8** %3
store i32* %1, i32** %4
%7 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 4
store i8 0, i8* %7
%8 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%9 = load i32*, i32** %4
%10 = call i32 @fread_err(i8* %8, i32 4, i32 1, i32* %9)
%11 = bitcast i32* %6 to i8*
%12 = load i32*, i32** %4
%13 = call i32 @fread_err(i8* %11, i32 4, i32 1, i32* %12)
%14 = load i32, i32* %6
%15 = icmp ne i32 %14, 8
br i1 %15, label %16, label %20
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%19 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0), i8* %18)
br label %20
20: ; preds = %16, %2
%21 = load i8*, i8** %3
%22 = load i32, i32* %6
%23 = load i32*, i32** %4
%24 = call i32 @fread_err(i8* %21, i32 %22, i32 1, i32* %23)
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [64 x i8] c"Error reading key '%s' expected 64 bit value, got 32 bit value\0A\00"
define void @toasim_read_64(i8* %0, i32* %1) {
%3 = alloca [8 x i8]
%4 = alloca i32
%5 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%6 = bitcast i32* %4 to i8*
%7 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 4
store i8 0, i8* %7
%8 = call i32 @fread_err(i8* %5, i32 4, i32 1, i32* %1)
%9 = call i32 @fread_err(i8* %6, i32 4, i32 1, i32* %1)
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, 8
br i1 %11, label %16, label %12
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0), i8* %5)
%15 = load i32, i32* %4
br label %16
16: ; preds = %12, %2
%17 = phi i32 [ %15, %12 ], [ 8, %2 ]
%18 = call i32 @fread_err(i8* %0, i32 %17, i32 1, i32* %1)
ret void
}