#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 size_t int64_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ _fread_fortran(char *, size_t, size_t, int /*<<< orphan*/ *, int);
size_t fread_fortran(void *ptr, size_t size, size_t nitems, FILE *stream,
                     int swap) {
  int64_t nread = 0;
  while (nread < nitems)
    nread += _fread_fortran(((char *)ptr) + (size * nread), size,
                            nitems - nread, stream, swap);
  return ((size_t)nread);
}


x86 assembly (clang, -O0):
<fread_fortran>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1178 <fread_fortran+0x68>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
imul   -0x30(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
sub    -0x30(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x24(%rbp),%r8d
call   1030 <_fread_fortran@plt>
add    -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    1134 <fread_fortran+0x24>
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fread_fortran>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdx,%rdx
je     1168 <fread_fortran+0x58>
mov    %r8d,%r14d
mov    %rcx,%r15
mov    %rdx,%rbp
mov    %rsi,%r12
mov    %rdi,%r13
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
imul   %r12,%rdi
add    %r13,%rdi
mov    %rbp,%rdx
sub    %rbx,%rdx
mov    %r12,%rsi
mov    %r15,%rcx
mov    %r14d,%r8d
call   1030 <_fread_fortran@plt>
add    %rax,%rbx
cmp    %rbp,%rbx
jb     1140 <fread_fortran+0x30>
jmp    116a <fread_fortran+0x5a>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i64 @fread_fortran(i8* %0, i64 %1, i64 %2, i32* %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i64
store i8* %0, i8** %6
store i64 %1, i64* %7
store i64 %2, i64* %8
store i32* %3, i32** %9
store i32 %4, i32* %10
store i64 0, i64* %11
br label %12
12: ; preds = %16, %5
%13 = load i64, i64* %11
%14 = load i64, i64* %8
%15 = icmp ult i64 %13, %14
br i1 %15, label %16, label %31
16: ; preds = %12
%17 = load i8*, i8** %6
%18 = load i64, i64* %7
%19 = load i64, i64* %11
%20 = mul i64 %18, %19
%21 = getelementptr inbounds i8, i8* %17, i64 %20
%22 = load i64, i64* %7
%23 = load i64, i64* %8
%24 = load i64, i64* %11
%25 = sub i64 %23, %24
%26 = load i32*, i32** %9
%27 = load i32, i32* %10
%28 = call i64 @_fread_fortran(i8* %21, i64 %22, i64 %25, i32* %26, i32 %27)
%29 = load i64, i64* %11
%30 = add i64 %29, %28
store i64 %30, i64* %11
br label %12
31: ; preds = %12
%32 = load i64, i64* %11
ret i64 %32
}

LLVM IR (-O2):
define i64 @fread_fortran(i8* %0, i64 %1, i64 %2, i32* %3, i32 %4) {
%6 = icmp eq i64 %2, 0
br i1 %6, label %15, label %7
7: ; preds = %5, %7
%8 = phi i64 [ %13, %7 ], [ 0, %5 ]
%9 = mul i64 %8, %1
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = sub i64 %2, %8
%12 = tail call i64 @_fread_fortran(i8* %10, i64 %1, i64 %11, i32* %3, i32 %4)
%13 = add i64 %12, %8
%14 = icmp ult i64 %13, %2
br i1 %14, label %7, label %15
15: ; preds = %7, %5
%16 = phi i64 [ 0, %5 ], [ %13, %7 ]
ret i64 %16
}