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

/* Variables and functions */
int EOF;
scalar_t__ ferror(int /*<<< orphan*/ *);
int getc(int /*<<< orphan*/ *);
int readrec_v1(int /*<<< orphan*/ *, struct acctv2 *);
int readrec_vx(int /*<<< orphan*/ *, struct acctv2 *);
int ungetc(int, int /*<<< orphan*/ *);
int readrec_forward(FILE *f, struct acctv2 *av2) {
  int magic, rv;
  if ((magic = getc(f)) == EOF)
    return (ferror(f) ? EOF : 0);
  if (ungetc(magic, f) == EOF)
    return (EOF);
  if (magic != 0)
    rv = readrec_v1(f, av2);
  else
    rv = readrec_vx(f, av2);
  return (rv == EOF ? EOF : 1);
}


x86 assembly (clang, -O0):
<readrec_forward>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <getc@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e75(%rip),%rcx
cmp    (%rcx),%eax
jne    11b4 <readrec_forward+0x64>
mov    -0x10(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     119f <readrec_forward+0x4f>
mov    0x2e53(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
jmp    11a9 <readrec_forward+0x59>
xor    %eax,%eax
mov    %eax,-0x24(%rbp)
jmp    11a9 <readrec_forward+0x59>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1245 <readrec_forward+0xf5>
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1060 <ungetc@plt>
mov    0x2e21(%rip),%rcx
cmp    (%rcx),%eax
jne    11e0 <readrec_forward+0x90>
mov    0x2e12(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1245 <readrec_forward+0xf5>
cmpl   $0x0,-0x1c(%rbp)
je     11ff <readrec_forward+0xaf>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <readrec_v1@plt>
mov    %eax,-0x20(%rbp)
jmp    120f <readrec_forward+0xbf>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <readrec_vx@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    0x2dcf(%rip),%rcx
cmp    (%rcx),%eax
jne    1232 <readrec_forward+0xe2>
mov    0x2dc0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
jmp    123f <readrec_forward+0xef>
mov    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    123f <readrec_forward+0xef>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readrec_forward>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1070 <getc@plt>
mov    %eax,%ebp
mov    0x2e7d(%rip),%r15
cmp    (%r15),%eax
jne    1184 <readrec_forward+0x34>
mov    %rbx,%rdi
call   1030 <ferror@plt>
xor    %ecx,%ecx
test   %rax,%rax
cmove  %ecx,%ebp
mov    %ebp,%eax
jmp    11b6 <readrec_forward+0x66>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1060 <ungetc@plt>
cmp    (%r15),%eax
je     11b6 <readrec_forward+0x66>
mov    %rbx,%rdi
mov    %r14,%rsi
test   %ebp,%ebp
je     11a4 <readrec_forward+0x54>
call   1050 <readrec_v1@plt>
jmp    11a9 <readrec_forward+0x59>
call   1040 <readrec_vx@plt>
mov    (%r15),%ecx
cmp    %ecx,%eax
mov    $0x1,%eax
cmove  %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.acctv2 = type { i32 }
@EOF = global i32 0
define i32 @readrec_forward(i32* %0, %struct.acctv2* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca %struct.acctv2*
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %4
store %struct.acctv2* %1, %struct.acctv2** %5
%8 = load i32*, i32** %4
%9 = call i32 @getc(i32* %8)
store i32 %9, i32* %6
%10 = load i32, i32* @EOF
%11 = icmp eq i32 %9, %10
br i1 %11, label %12, label %21
12: ; preds = %2
%13 = load i32*, i32** %4
%14 = call i64 @ferror(i32* %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = load i32, i32* @EOF
br label %19
18: ; preds = %12
br label %19
19: ; preds = %18, %16
%20 = phi i32 [ %17, %16 ], [ 0, %18 ]
store i32 %20, i32* %3
br label %49
21: ; preds = %2
%22 = load i32, i32* %6
%23 = load i32*, i32** %4
%24 = call i32 @ungetc(i32 %22, i32* %23)
%25 = load i32, i32* @EOF
%26 = icmp eq i32 %24, %25
br i1 %26, label %27, label %29
27: ; preds = %21
%28 = load i32, i32* @EOF
store i32 %28, i32* %3
br label %49
29: ; preds = %21
%30 = load i32, i32* %6
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %29
%33 = load i32*, i32** %4
%34 = load %struct.acctv2*, %struct.acctv2** %5
%35 = call i32 @readrec_v1(i32* %33, %struct.acctv2* %34)
store i32 %35, i32* %7
br label %40
36: ; preds = %29
%37 = load i32*, i32** %4
%38 = load %struct.acctv2*, %struct.acctv2** %5
%39 = call i32 @readrec_vx(i32* %37, %struct.acctv2* %38)
store i32 %39, i32* %7
br label %40
40: ; preds = %36, %32
%41 = load i32, i32* %7
%42 = load i32, i32* @EOF
%43 = icmp eq i32 %41, %42
br i1 %43, label %44, label %46
44: ; preds = %40
%45 = load i32, i32* @EOF
br label %47
46: ; preds = %40
br label %47
47: ; preds = %46, %44
%48 = phi i32 [ %45, %44 ], [ 1, %46 ]
store i32 %48, i32* %3
br label %49
49: ; preds = %47, %27, %19
%50 = load i32, i32* %3
ret i32 %50
}

LLVM IR (-O2):
%struct.acctv2 = type { i32 }
@EOF = global i32 0
define i32 @readrec_forward(i32* %0, %struct.acctv2* %1) {
%3 = tail call i32 @getc(i32* %0)
%4 = load i32, i32* @EOF
%5 = icmp eq i32 %3, %4
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = tail call i64 @ferror(i32* %0)
%8 = icmp eq i64 %7, 0
%9 = select i1 %8, i32 0, i32 %3
br label %25
10: ; preds = %2
%11 = tail call i32 @ungetc(i32 %3, i32* %0)
%12 = load i32, i32* @EOF
%13 = icmp eq i32 %11, %12
br i1 %13, label %25, label %14
14: ; preds = %10
%15 = icmp eq i32 %3, 0
br i1 %15, label %18, label %16
16: ; preds = %14
%17 = tail call i32 @readrec_v1(i32* %0, %struct.acctv2* %1)
br label %20
18: ; preds = %14
%19 = tail call i32 @readrec_vx(i32* %0, %struct.acctv2* %1)
br label %20
20: ; preds = %18, %16
%21 = phi i32 [ %17, %16 ], [ %19, %18 ]
%22 = load i32, i32* @EOF
%23 = icmp eq i32 %21, %22
%24 = select i1 %23, i32 %22, i32 1
br label %25
25: ; preds = %10, %20, %6
%26 = phi i32 [ %9, %6 ], [ %24, %20 ], [ %11, %10 ]
ret i32 %26
}