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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ read32(int, scalar_t__, int /*<<< orphan*/ *);
scalar_t__ read8(int, scalar_t__, int *);
int /*<<< orphan*/ stderr;
int readcons(int fd, off_t addr, uint32_t *car, uint32_t *cdr) {
  uint8_t type;
  if (read8(fd, addr, &type)) {
    fprintf(stderr, "persist: readcons: failed to read type\n");
    return (1);
  }
  if ((type & 0xF0) != 0x00) {
    fprintf(stderr, "persist: readcons: type!=T_CONS\n");
    return (2);
  }
  if (read32(fd, addr + 1, car)) {
    fprintf(stderr, "persist: readcons: failed to read car\n");
    return (1);
  }
  if (read32(fd, addr + 5, cdr)) {
    fprintf(stderr, "persist: readcons: failed to read cdr\n");
    return (1);
  }
  return (0);
}


x86 assembly (clang, -O0):
<readcons>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    -0x24(%rbp),%rdx
call   1030 <read8@plt>
cmp    $0x0,%rax
je     1182 <readcons+0x52>
mov    0x2e78(%rip),%rax
mov    (%rax),%edi
lea    0xe8f(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1239 <readcons+0x109>
mov    -0x24(%rbp),%eax
and    $0xf0,%eax
cmp    $0x0,%eax
je     11b4 <readcons+0x84>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
lea    0xe85(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1239 <readcons+0x109>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
add    $0x1,%rsi
mov    -0x18(%rbp),%rdx
call   1050 <read32@plt>
cmp    $0x0,%rax
je     11f3 <readcons+0xc3>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
lea    0xe67(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1239 <readcons+0x109>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
add    $0x5,%rsi
mov    -0x20(%rbp),%rdx
call   1050 <read32@plt>
cmp    $0x0,%rax
je     1232 <readcons+0x102>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
lea    0xe4f(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1239 <readcons+0x109>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readcons>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%r14
mov    %rdx,%r12
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xc(%rsp),%rdx
call   1030 <read8@plt>
mov    $0x1,%r15d
test   %rax,%rax
je     1165 <readcons+0x35>
lea    0xe9d(%rip),%rsi
jmp    11b4 <readcons+0x84>
testb  $0xf0,0xc(%rsp)
je     117b <readcons+0x4b>
mov    $0x2,%r15d
lea    0xeaf(%rip),%rsi
jmp    11b4 <readcons+0x84>
lea    0x1(%rbx),%rsi
mov    %ebp,%edi
mov    %r12,%rdx
call   1050 <read32@plt>
test   %rax,%rax
je     1197 <readcons+0x67>
lea    0xeb4(%rip),%rsi
jmp    11b4 <readcons+0x84>
add    $0x5,%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1050 <read32@plt>
test   %rax,%rax
je     11d2 <readcons+0xa2>
lea    0xebc(%rip),%rsi
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
call   1040 <fprintf@plt>
mov    %r15d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %r15d,%r15d
jmp    11c2 <readcons+0x92>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [40 x i8] c"persist: readcons: failed to read type\0A\00"
@.str.1 = [33 x i8] c"persist: readcons: type!=T_CONS\0A\00"
@.str.2 = [39 x i8] c"persist: readcons: failed to read car\0A\00"
@.str.3 = [39 x i8] c"persist: readcons: failed to read cdr\0A\00"
define i32 @readcons(i32 %0, i64 %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
store i32 %0, i32* %6
store i64 %1, i64* %7
store i32* %2, i32** %8
store i32* %3, i32** %9
%11 = load i32, i32* %6
%12 = load i64, i64* %7
%13 = call i64 @read8(i32 %11, i64 %12, i32* %10)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %4
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %5
br label %46
18: ; preds = %4
%19 = load i32, i32* %10
%20 = and i32 %19, 240
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
store i32 2, i32* %5
br label %46
25: ; preds = %18
%26 = load i32, i32* %6
%27 = load i64, i64* %7
%28 = add nsw i64 %27, 1
%29 = load i32*, i32** %8
%30 = call i64 @read32(i32 %26, i64 %28, i32* %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %25
%33 = load i32, i32* @stderr
%34 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %5
br label %46
35: ; preds = %25
%36 = load i32, i32* %6
%37 = load i64, i64* %7
%38 = add nsw i64 %37, 5
%39 = load i32*, i32** %9
%40 = call i64 @read32(i32 %36, i64 %38, i32* %39)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %35
%43 = load i32, i32* @stderr
%44 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %5
br label %46
45: ; preds = %35
store i32 0, i32* %5
br label %46
46: ; preds = %45, %42, %32, %22, %15
%47 = load i32, i32* %5
ret i32 %47
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [40 x i8] c"persist: readcons: failed to read type\0A\00"
@.str.1 = [33 x i8] c"persist: readcons: type!=T_CONS\0A\00"
@.str.2 = [39 x i8] c"persist: readcons: failed to read car\0A\00"
@.str.3 = [39 x i8] c"persist: readcons: failed to read cdr\0A\00"
define i32 @readcons(i32 %0, i64 %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
%7 = call i64 @read8(i32 %0, i64 %1, i32* %5)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %21
9: ; preds = %4
%10 = load i32, i32* %5
%11 = and i32 %10, 240
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %21
13: ; preds = %9
%14 = add nsw i64 %1, 1
%15 = call i64 @read32(i32 %0, i64 %14, i32* %2)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %13
%18 = add nsw i64 %1, 5
%19 = call i64 @read32(i32 %0, i64 %18, i32* %3)
%20 = icmp eq i64 %19, 0
br i1 %20, label %26, label %21
21: ; preds = %17, %13, %9, %4
%22 = phi i8* [ getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), %4 ], [ getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), %9 ], [ getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), %13 ], [ getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), %17 ]
%23 = phi i32 [ 1, %4 ], [ 2, %9 ], [ 1, %13 ], [ 1, %17 ]
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* %22)
br label %26
26: ; preds = %21, %17
%27 = phi i32 [ 0, %17 ], [ %23, %21 ]
ret i32 %27
}