#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int INT_MAX;
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int get_fsize(FILE *f) {
  int r;
  for (r = 0; r < INT_MAX && !feof(f) && fgetc(f) != -1; ++r) {
  }
  if (r == INT_MAX) {
    r = -1;
  }
  rewind(f);
  return r;
}


x86 assembly (clang, -O0):
<get_fsize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%ecx
xor    %eax,%eax
mov    0x2e99(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0xd(%rbp)
jge    1185 <get_fsize+0x55>
mov    -0x8(%rbp),%rdi
call   1050 <feof@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0xd(%rbp)
jne    1185 <get_fsize+0x55>
mov    -0x8(%rbp),%rdi
call   1040 <fgetc@plt>
cmp    $0xffffffff,%eax
setne  %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    1195 <get_fsize+0x65>
jmp    11a8 <get_fsize+0x78>
jmp    119a <get_fsize+0x6a>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1143 <get_fsize+0x13>
mov    -0xc(%rbp),%eax
mov    0x2e36(%rip),%rcx
cmp    (%rcx),%eax
jne    11c1 <get_fsize+0x91>
movl   $0xffffffff,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <rewind@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_fsize>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    0x2eaa(%rip),%r14
mov    (%r14),%eax
xor    %ebp,%ebp
test   %eax,%eax
jle    1174 <get_fsize+0x44>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1050 <feof@plt>
test   %eax,%eax
jne    1171 <get_fsize+0x41>
mov    %rbx,%rdi
call   1040 <fgetc@plt>
cmp    $0xffffffff,%eax
je     1171 <get_fsize+0x41>
add    $0x1,%ebp
cmp    (%r14),%ebp
jl     1150 <get_fsize+0x20>
mov    (%r14),%eax
cmp    %eax,%ebp
mov    $0xffffffff,%r14d
cmovne %ebp,%r14d
mov    %rbx,%rdi
call   1030 <rewind@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@INT_MAX = global i32 0
define i32 @get_fsize(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
store i32* %0, i32** %2
store i32 0, i32* %3
br label %4
4: ; preds = %19, %1
%5 = load i32, i32* %3
%6 = load i32, i32* @INT_MAX
%7 = icmp slt i32 %5, %6
br i1 %7, label %8, label %16
8: ; preds = %4
%9 = load i32*, i32** %2
%10 = call i32 @feof(i32* %9)
%11 = icmp ne i32 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %8
%13 = load i32*, i32** %2
%14 = call i32 @fgetc(i32* %13)
%15 = icmp ne i32 %14, -1
br label %16
16: ; preds = %12, %8, %4
%17 = phi i1 [ false, %8 ], [ false, %4 ], [ %15, %12 ]
br i1 %17, label %18, label %22
18: ; preds = %16
br label %19
19: ; preds = %18
%20 = load i32, i32* %3
%21 = add nsw i32 %20, 1
store i32 %21, i32* %3
br label %4
22: ; preds = %16
%23 = load i32, i32* %3
%24 = load i32, i32* @INT_MAX
%25 = icmp eq i32 %23, %24
br i1 %25, label %26, label %27
26: ; preds = %22
store i32 -1, i32* %3
br label %27
27: ; preds = %26, %22
%28 = load i32*, i32** %2
%29 = call i32 @rewind(i32* %28)
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
@INT_MAX = global i32 0
define i32 @get_fsize(i32* nocapture %0) {
%2 = load i32, i32* @INT_MAX
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %18
4: ; preds = %1, %11
%5 = phi i32 [ %12, %11 ], [ 0, %1 ]
%6 = tail call i32 @feof(i32* %0)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %15
8: ; preds = %4
%9 = tail call i32 @fgetc(i32* %0)
%10 = icmp eq i32 %9, -1
br i1 %10, label %15, label %11
11: ; preds = %8
%12 = add nuw nsw i32 %5, 1
%13 = load i32, i32* @INT_MAX
%14 = icmp slt i32 %12, %13
br i1 %14, label %4, label %15
15: ; preds = %11, %4, %8
%16 = phi i32 [ %5, %8 ], [ %5, %4 ], [ %12, %11 ]
%17 = load i32, i32* @INT_MAX
br label %18
18: ; preds = %15, %1
%19 = phi i32 [ %2, %1 ], [ %17, %15 ]
%20 = phi i32 [ 0, %1 ], [ %16, %15 ]
%21 = icmp eq i32 %20, %19
%22 = select i1 %21, i32 -1, i32 %20
%23 = tail call i32 @rewind(i32* %0)
ret i32 %22
}