#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_32(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 != 4) {
    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_32>:
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   $0x4,-0x1c(%rbp)
je     1185 <toasim_read_32+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_32>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
movb   $0x0,0xc(%rsp)
lea    0x8(%rsp),%rdi
mov    $0x4,%ebp
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread_err@plt>
lea    0x4(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread_err@plt>
cmpl   $0x4,0x4(%rsp)
je     118b <toasim_read_32+0x6b>
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
lea    0xe83(%rip),%rsi
lea    0x8(%rsp),%rdx
call   1030 <fprintf@plt>
mov    0x4(%rsp),%ebp
mov    %r14,%rdi
mov    %ebp,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread_err@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
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_32(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, 4
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_32(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, 4
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 ], [ 4, %2 ]
%18 = call i32 @fread_err(i8* %0, i32 %17, i32 1, i32* %1)
ret void
}