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

/* Variables and functions */
int /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
long file_size(char const *);
int /*<<< orphan*/ *fopen(char const *, char *);
scalar_t__ fread(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseeko(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(float *, int *, int);
int /*<<< orphan*/ printf(char *, int, int, int, int);
int /*<<< orphan*/ stdout;
int u4_from_buffer(int /*<<< orphan*/ *);
int get_xtc_num_frames(const char *filename, int *nframes, int *natoms,
                       float *psec, bool quiet) {
  uint8_t header[92];
  uint32_t frame_size;
  uint32_t skip;
  uint32_t ps_tmp;
  long size = file_size(filename);
  double avg_frame_size = 0.;
  int est_nframes = 0;
  FILE *xtc = fopen(filename, "rb");
  if (!xtc)
    return -1;
  *nframes = 0;
  while (fread(header, 92, 1, xtc)) {
    (*nframes)++;
    *natoms = u4_from_buffer(header + 4);
    frame_size = u4_from_buffer(header + 88);
    skip = (frame_size + 3) & ~((uint32_t)3);
    avg_frame_size += (skip - avg_frame_size + 92) / *nframes;
    if (!quiet && *nframes % 100 == 0) {
      est_nframes = (int)(size / avg_frame_size);
      ps_tmp = u4_from_buffer(header + 12);
      memcpy(psec, &ps_tmp, 4);
      *psec *= (double)est_nframes / *nframes;
      printf("\rEstimated %'d frames (%'d ns) of %'d atoms. - %d%%",
             est_nframes, (int)(*psec / 1000), *natoms,
             (int)(100. * *nframes) / est_nframes);
      fflush(stdout);
    }
    fseeko(xtc, skip, SEEK_CUR);
  }
  ps_tmp = u4_from_buffer(header + 12);
  memcpy(psec, &ps_tmp, 4);
  fclose(xtc);
  return 0;
}


x86 assembly (clang, -O0):
<get_xtc_num_frames>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1e0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <file_size@plt>
mov    %rax,-0x1b8(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x1c0(%rbp)
ff
movl   $0x0,-0x1c4(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe35(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x1d0(%rbp)
cmpq   $0x0,-0x1d0(%rbp)
jne    1205 <get_xtc_num_frames+0x75>
movl   $0xffffffff,-0x4(%rbp)
jmp    1419 <get_xtc_num_frames+0x289>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
lea    -0x1a0(%rbp),%rdi
mov    -0x1d0(%rbp),%rcx
mov    $0x5c,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
cmp    $0x0,%rax
je     13db <get_xtc_num_frames+0x24b>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
lea    -0x1a0(%rbp),%rdi
add    $0x10,%rdi
call   1030 <u4_from_buffer@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
lea    -0x1a0(%rbp),%rdi
add    $0x160,%rdi
call   1030 <u4_from_buffer@plt>
mov    %eax,-0x1a4(%rbp)
mov    -0x1a4(%rbp),%eax
add    $0x3,%eax
and    $0xfffffffc,%eax
mov    %eax,-0x1a8(%rbp)
cvtsi2sdl -0x1a8(%rbp),%xmm0
ff
subsd  -0x1c0(%rbp),%xmm0
ff
movsd  0xd64(%rip),%xmm1
addsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
cvtsi2sdl (%rax),%xmm1
divsd  %xmm1,%xmm0
addsd  -0x1c0(%rbp),%xmm0
ff
movsd  %xmm0,-0x1c0(%rbp)
ff
cmpl   $0x0,-0x2c(%rbp)
jne    13bb <get_xtc_num_frames+0x22b>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    13bb <get_xtc_num_frames+0x22b>
cvtsi2sdq -0x1b8(%rbp),%xmm0
ff ff
divsd  -0x1c0(%rbp),%xmm0
ff
cvttsd2si %xmm0,%eax
mov    %eax,-0x1c4(%rbp)
lea    -0x1a0(%rbp),%rdi
add    $0x30,%rdi
call   1030 <u4_from_buffer@plt>
mov    %eax,-0x1ac(%rbp)
mov    -0x28(%rbp),%rdi
lea    -0x1ac(%rbp),%rsi
mov    $0x4,%edx
call   1080 <memcpy@plt>
cvtsi2sdl -0x1c4(%rbp),%xmm1
ff
mov    -0x18(%rbp),%rax
cvtsi2sdl (%rax),%xmm0
divsd  %xmm0,%xmm1
mov    -0x28(%rbp),%rax
movss  (%rax),%xmm0
cvtss2sd %xmm0,%xmm0
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,(%rax)
mov    -0x1c4(%rbp),%esi
mov    -0x28(%rbp),%rax
movss  (%rax),%xmm0
movss  0xcab(%rip),%xmm1
divss  %xmm1,%xmm0
cvttss2si %xmm0,%eax
mov    %eax,-0x1d4(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
cvtsi2sdl (%rax),%xmm1
movsd  0xc7f(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
cltd
idivl  -0x1c4(%rbp)
mov    -0x1d4(%rbp),%edx
mov    %eax,%r8d
lea    0xc6f(%rip),%rdi
call   1060 <printf@plt>
mov    0x2c24(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
mov    -0x1d0(%rbp),%rdi
mov    -0x1a8(%rbp),%esi
mov    0x2c19(%rip),%rax
mov    (%rax),%edx
call   10a0 <fseeko@plt>
jmp    120f <get_xtc_num_frames+0x7f>
lea    -0x1a0(%rbp),%rdi
add    $0x30,%rdi
call   1030 <u4_from_buffer@plt>
mov    %eax,-0x1ac(%rbp)
mov    -0x28(%rbp),%rdi
lea    -0x1ac(%rbp),%rsi
mov    $0x4,%edx
call   1080 <memcpy@plt>
mov    -0x1d0(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1e0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_xtc_num_frames>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1c8,%rsp
mov    %r8d,0x1c(%rsp)
mov    %rcx,0x20(%rsp)
mov    %rdx,0x28(%rsp)
mov    %rsi,%r14
mov    %rdi,%rbx
call   1070 <file_size@plt>
mov    %rax,%r15
lea    0xe4f(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <fopen@plt>
test   %rax,%rax
je     13cc <get_xtc_num_frames+0x23c>
mov    %rax,%rbx
movl   $0x0,(%r14)
lea    0x50(%rsp),%rdi
mov    $0x5c,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
test   %rax,%rax
je     139b <get_xtc_num_frames+0x20b>
lea    0x60(%rsp),%r12
lea    0x1b0(%rsp),%rbp
cvtsi2sd %r15,%xmm0
movsd  %xmm0,0x30(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
mov    0x2dbf(%rip),%r15
mov    %rbx,0x38(%rsp)
jmp    125e <get_xtc_num_frames+0xce>
mov    (%r15),%edx
mov    %rbx,%rdi
mov    %r13d,%esi
call   10a0 <fseeko@plt>
lea    0x50(%rsp),%rdi
mov    $0x5c,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
test   %rax,%rax
je     139b <get_xtc_num_frames+0x20b>
addl   $0x1,(%r14)
mov    %r12,%rdi
call   1030 <u4_from_buffer@plt>
mov    0x28(%rsp),%rcx
mov    %eax,(%rcx)
mov    %rbp,%rdi
call   1030 <u4_from_buffer@plt>
mov    %eax,%r13d
add    $0x3,%r13d
and    $0xfffffffc,%r13d
xorps  %xmm1,%xmm1
cvtsi2sd %r13d,%xmm1
movsd  0x10(%rsp),%xmm2
subsd  %xmm2,%xmm1
addsd  0xd62(%rip),%xmm1
movslq (%r14),%rax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  %xmm0,%xmm1
addsd  %xmm2,%xmm1
movsd  %xmm1,0x10(%rsp)
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rcx
add    %edx,%ecx
imul   $0x64,%ecx,%ecx
sub    %ecx,%eax
or     0x1c(%rsp),%eax
jne    1230 <get_xtc_num_frames+0xa0>
movsd  0x30(%rsp),%xmm0
divsd  0x10(%rsp),%xmm0
movapd %xmm0,0x40(%rsp)
cvttsd2si %xmm0,%r15d
lea    0x80(%rsp),%rdi
call   1030 <u4_from_buffer@plt>
mov    %eax,0xc(%rsp)
mov    0x20(%rsp),%rbx
mov    %rbx,%rdi
lea    0xc(%rsp),%rsi
mov    $0x4,%edx
call   1080 <memcpy@plt>
cvttpd2dq 0x40(%rsp),%xmm0
cvtdq2pd %xmm0,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sdl (%r14),%xmm1
divsd  %xmm1,%xmm0
movss  (%rbx),%xmm2
cvtss2sd %xmm2,%xmm2
mulsd  %xmm0,%xmm2
xorps  %xmm0,%xmm0
cvtsd2ss %xmm2,%xmm0
movss  %xmm0,(%rbx)
divss  0xcc3(%rip),%xmm0
cvttss2si %xmm0,%ebx
mov    0x28(%rsp),%rax
mov    (%rax),%ecx
mulsd  0xca8(%rip),%xmm1
cvttsd2si %xmm1,%eax
cltd
idiv   %r15d
lea    0xca8(%rip),%rdi
mov    %r15d,%esi
mov    0x2c6f(%rip),%r15
mov    %ebx,%edx
mov    0x38(%rsp),%rbx
mov    %eax,%r8d
call   1060 <printf@plt>
mov    0x2c49(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
jmp    1230 <get_xtc_num_frames+0xa0>
lea    0x80(%rsp),%rdi
call   1030 <u4_from_buffer@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rsi
mov    0x20(%rsp),%rdi
mov    $0x4,%edx
call   1080 <memcpy@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
jmp    13d1 <get_xtc_num_frames+0x241>
mov    $0xffffffff,%eax
add    $0x1c8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [52 x i8] c"\0DEstimated %'d frames (%'d ns) of %'d atoms. - %d%%\00"
@stdout = global i32 0
@SEEK_CUR = global i32 0
define i32 @get_xtc_num_frames(i8* %0, i32* %1, i32* %2, float* %3, i32 %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca float*
%11 = alloca i32
%12 = alloca [92 x i32]
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i64
%17 = alloca double
%18 = alloca i32
%19 = alloca i32*
store i8* %0, i8** %7
store i32* %1, i32** %8
store i32* %2, i32** %9
store float* %3, float** %10
store i32 %4, i32* %11
%20 = load i8*, i8** %7
%21 = call i64 @file_size(i8* %20)
store i64 %21, i64* %16
store double 0.000000e+00, double* %17
store i32 0, i32* %18
%22 = load i8*, i8** %7
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %23, i32** %19
%24 = load i32*, i32** %19
%25 = icmp ne i32* %24, null
br i1 %25, label %27, label %26
26: ; preds = %5
store i32 -1, i32* %6
br label %118
27: ; preds = %5
%28 = load i32*, i32** %8
store i32 0, i32* %28
br label %29
29: ; preds = %105, %27
%30 = getelementptr inbounds [92 x i32], [92 x i32]* %12, i64 0, i64 0
%31 = load i32*, i32** %19
%32 = call i64 @fread(i32* %30, i32 92, i32 1, i32* %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %110
34: ; preds = %29
%35 = load i32*, i32** %8
%36 = load i32, i32* %35
%37 = add nsw i32 %36, 1
store i32 %37, i32* %35
%38 = getelementptr inbounds [92 x i32], [92 x i32]* %12, i64 0, i64 0
%39 = getelementptr inbounds i32, i32* %38, i64 4
%40 = call i32 @u4_from_buffer(i32* %39)
%41 = load i32*, i32** %9
store i32 %40, i32* %41
%42 = getelementptr inbounds [92 x i32], [92 x i32]* %12, i64 0, i64 0
%43 = getelementptr inbounds i32, i32* %42, i64 88
%44 = call i32 @u4_from_buffer(i32* %43)
store i32 %44, i32* %13
%45 = load i32, i32* %13
%46 = add nsw i32 %45, 3
%47 = and i32 %46, -4
store i32 %47, i32* %14
%48 = load i32, i32* %14
%49 = sitofp i32 %48 to double
%50 = load double, double* %17
%51 = fsub double %49, %50
%52 = fadd double %51, 9.200000e+01
%53 = load i32*, i32** %8
%54 = load i32, i32* %53
%55 = sitofp i32 %54 to double
%56 = fdiv double %52, %55
%57 = load double, double* %17
%58 = fadd double %57, %56
store double %58, double* %17
%59 = load i32, i32* %11
%60 = icmp ne i32 %59, 0
br i1 %60, label %105, label %61
61: ; preds = %34
%62 = load i32*, i32** %8
%63 = load i32, i32* %62
%64 = srem i32 %63, 100
%65 = icmp eq i32 %64, 0
br i1 %65, label %66, label %105
66: ; preds = %61
%67 = load i64, i64* %16
%68 = sitofp i64 %67 to double
%69 = load double, double* %17
%70 = fdiv double %68, %69
%71 = fptosi double %70 to i32
store i32 %71, i32* %18
%72 = getelementptr inbounds [92 x i32], [92 x i32]* %12, i64 0, i64 0
%73 = getelementptr inbounds i32, i32* %72, i64 12
%74 = call i32 @u4_from_buffer(i32* %73)
store i32 %74, i32* %15
%75 = load float*, float** %10
%76 = call i32 @memcpy(float* %75, i32* %15, i32 4)
%77 = load i32, i32* %18
%78 = sitofp i32 %77 to double
%79 = load i32*, i32** %8
%80 = load i32, i32* %79
%81 = sitofp i32 %80 to double
%82 = fdiv double %78, %81
%83 = load float*, float** %10
%84 = load float, float* %83
%85 = fpext float %84 to double
%86 = fmul double %85, %82
%87 = fptrunc double %86 to float
store float %87, float* %83
%88 = load i32, i32* %18
%89 = load float*, float** %10
%90 = load float, float* %89
%91 = fdiv float %90, 1.000000e+03
%92 = fptosi float %91 to i32
%93 = load i32*, i32** %9
%94 = load i32, i32* %93
%95 = load i32*, i32** %8
%96 = load i32, i32* %95
%97 = sitofp i32 %96 to double
%98 = fmul double 1.000000e+02, %97
%99 = fptosi double %98 to i32
%100 = load i32, i32* %18
%101 = sdiv i32 %99, %100
%102 = call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i32 %88, i32 %92, i32 %94, i32 %101)
%103 = load i32, i32* @stdout
%104 = call i32 @fflush(i32 %103)
br label %105
105: ; preds = %66, %61, %34
%106 = load i32*, i32** %19
%107 = load i32, i32* %14
%108 = load i32, i32* @SEEK_CUR
%109 = call i32 @fseeko(i32* %106, i32 %107, i32 %108)
br label %29
110: ; preds = %29
%111 = getelementptr inbounds [92 x i32], [92 x i32]* %12, i64 0, i64 0
%112 = getelementptr inbounds i32, i32* %111, i64 12
%113 = call i32 @u4_from_buffer(i32* %112)
store i32 %113, i32* %15
%114 = load float*, float** %10
%115 = call i32 @memcpy(float* %114, i32* %15, i32 4)
%116 = load i32*, i32** %19
%117 = call i32 @fclose(i32* %116)
store i32 0, i32* %6
br label %118
118: ; preds = %110, %26
%119 = load i32, i32* %6
ret i32 %119
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [52 x i8] c"\0DEstimated %'d frames (%'d ns) of %'d atoms. - %d%%\00"
@stdout = global i32 0
@SEEK_CUR = global i32 0
define i32 @get_xtc_num_frames(i8* %0, i32* nocapture %1, i32* nocapture %2, float* %3, i32 %4) {
%6 = alloca [92 x i32]
%7 = alloca i32
%8 = bitcast [92 x i32]* %6 to i8*
%9 = bitcast i32* %7 to i8*
%10 = tail call i64 @file_size(i8* %0)
%11 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %73, label %13
13: ; preds = %5
store i32 0, i32* %1
%14 = getelementptr inbounds [92 x i32], [92 x i32]* %6, i64 0, i64 0
%15 = call i64 @fread(i32* %14, i32 92, i32 1, i32* %11)
%16 = icmp eq i64 %15, 0
br i1 %16, label %68, label %17
17: ; preds = %13
%18 = getelementptr inbounds [92 x i32], [92 x i32]* %6, i64 0, i64 4
%19 = getelementptr inbounds [92 x i32], [92 x i32]* %6, i64 0, i64 88
%20 = icmp eq i32 %4, 0
%21 = sitofp i64 %10 to double
%22 = getelementptr inbounds [92 x i32], [92 x i32]* %6, i64 0, i64 12
br label %23
23: ; preds = %17, %63
%24 = phi double [ 0.000000e+00, %17 ], [ %37, %63 ]
%25 = load i32, i32* %1
%26 = add nsw i32 %25, 1
store i32 %26, i32* %1
%27 = call i32 @u4_from_buffer(i32* %18)
store i32 %27, i32* %2
%28 = call i32 @u4_from_buffer(i32* %19)
%29 = add nsw i32 %28, 3
%30 = and i32 %29, -4
%31 = sitofp i32 %30 to double
%32 = fsub double %31, %24
%33 = fadd double %32, 9.200000e+01
%34 = load i32, i32* %1
%35 = sitofp i32 %34 to double
%36 = fdiv double %33, %35
%37 = fadd double %24, %36
%38 = srem i32 %34, 100
%39 = icmp eq i32 %38, 0
%40 = select i1 %20, i1 %39, i1 false
br i1 %40, label %41, label %63
41: ; preds = %23
%42 = fdiv double %21, %37
%43 = fptosi double %42 to i32
%44 = call i32 @u4_from_buffer(i32* %22)
store i32 %44, i32* %7
%45 = call i32 @memcpy(float* %3, i32* %7, i32 4)
%46 = sitofp i32 %43 to double
%47 = load i32, i32* %1
%48 = sitofp i32 %47 to double
%49 = fdiv double %46, %48
%50 = load float, float* %3
%51 = fpext float %50 to double
%52 = fmul double %49, %51
%53 = fptrunc double %52 to float
store float %53, float* %3
%54 = fdiv float %53, 1.000000e+03
%55 = fptosi float %54 to i32
%56 = load i32, i32* %2
%57 = fmul double %48, 1.000000e+02
%58 = fptosi double %57 to i32
%59 = sdiv i32 %58, %43
%60 = call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i32 %43, i32 %55, i32 %56, i32 %59)
%61 = load i32, i32* @stdout
%62 = call i32 @fflush(i32 %61)
br label %63
63: ; preds = %41, %23
%64 = load i32, i32* @SEEK_CUR
%65 = call i32 @fseeko(i32* %11, i32 %30, i32 %64)
%66 = call i64 @fread(i32* %14, i32 92, i32 1, i32* %11)
%67 = icmp eq i64 %66, 0
br i1 %67, label %68, label %23
68: ; preds = %63, %13
%69 = getelementptr inbounds [92 x i32], [92 x i32]* %6, i64 0, i64 12
%70 = call i32 @u4_from_buffer(i32* %69)
store i32 %70, i32* %7
%71 = call i32 @memcpy(float* %3, i32* %7, i32 4)
%72 = call i32 @fclose(i32* %11)
br label %73
73: ; preds = %5, %68
%74 = phi i32 [ 0, %68 ], [ -1, %5 ]
ret i32 %74
}