#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 /*<<< orphan*/ BUFSIZ;
scalar_t__ EOF;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(short *, int, int, int /*<<< orphan*/ *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int nr_timesteps(char pp[BUFSIZ + 1], int cc, int binflag) {
  FILE *fp1;
  char str1[BUFSIZ + 1];
  short int dummy;
  long i;
  int r;
  if (binflag != 1) {
    if ((fp1 = fopen(pp, "r")) == NULL) {
      printf("Cannot open file %s \n", pp);
      exit(0);
    }
  } else {
    if ((fp1 = fopen(pp, "rb")) == NULL) {
      printf("Cannot open file %s \n", pp);
      exit(0);
    }
  }
  i = 0;
  if (binflag != 1) {
    while (fscanf(fp1, "%s", str1) != EOF)
      i++;
  } else {
    while (!feof(fp1)) {
      fread(&dummy, 2, 1, fp1);
      i++;
    }
  }
  r = (int)(i / cc);
  fclose(fp1);
  return r;
}


x86 assembly (clang, -O0):
<nr_timesteps>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    0x2e4f(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
cmpl   $0x1,-0x10(%rbp)
je     11f5 <nr_timesteps+0x85>
mov    -0x8(%rbp),%rdi
lea    0xe3a(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11f0 <nr_timesteps+0x80>
mov    -0x8(%rbp),%rsi
lea    0xe1e(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
jmp    122f <nr_timesteps+0xbf>
mov    -0x8(%rbp),%rdi
lea    0xe18(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    122a <nr_timesteps+0xba>
mov    -0x8(%rbp),%rsi
lea    0xde4(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
jmp    122f <nr_timesteps+0xbf>
movq   $0x0,-0x38(%rbp)
cmpl   $0x1,-0x10(%rbp)
je     1280 <nr_timesteps+0x110>
jmp    1246 <nr_timesteps+0xd6>
mov    -0x48(%rbp),%rdx
mov    -0x18(%rbp),%rdi
lea    0xdc6(%rip),%rsi
call   1060 <fscanf@plt>
mov    0x2d87(%rip),%rcx
cmp    (%rcx),%rax
je     127b <nr_timesteps+0x10b>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    1246 <nr_timesteps+0xd6>
jmp    12d0 <nr_timesteps+0x160>
jmp    1285 <nr_timesteps+0x115>
mov    -0x18(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    12a3 <nr_timesteps+0x133>
jmp    12cb <nr_timesteps+0x15b>
mov    -0x18(%rbp),%rcx
lea    -0x2a(%rbp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    1285 <nr_timesteps+0x115>
jmp    12d0 <nr_timesteps+0x160>
mov    -0x38(%rbp),%rax
movslq -0xc(%rbp),%rcx
cqto
idiv   %rcx
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x3c(%rbp),%eax
mov    -0x20(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nr_timesteps>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%rbx
mov    0x2e4d(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%r12
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
cmp    $0x1,%edx
jne    1207 <nr_timesteps+0x97>
lea    0xe6b(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     1299 <nr_timesteps+0x129>
mov    %rax,%r15
mov    %rax,%rdi
call   1070 <feof@plt>
xor    %ebx,%ebx
test   %eax,%eax
jne    125b <nr_timesteps+0xeb>
lea    -0x2e(%rbp),%r12
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
add    $0x1,%rbx
mov    %r15,%rdi
call   1070 <feof@plt>
test   %eax,%eax
je     11e0 <nr_timesteps+0x70>
jmp    125b <nr_timesteps+0xeb>
mov    %r14d,-0x2c(%rbp)
lea    0xdee(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     1299 <nr_timesteps+0x129>
mov    %rax,%r15
mov    $0xffffffffffffffff,%rbx
lea    0xdeb(%rip),%r13
mov    0x2db1(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
call   1060 <fscanf@plt>
add    $0x1,%rbx
cmp    (%r14),%rax
jne    1240 <nr_timesteps+0xd0>
mov    -0x2c(%rbp),%r14d
movslq %r14d,%rcx
mov    %rbx,%rax
or     %rcx,%rax
shr    $0x20,%rax
je     1277 <nr_timesteps+0x107>
mov    %rbx,%rax
cqto
idiv   %rcx
mov    %rax,%rbx
jmp    1280 <nr_timesteps+0x110>
mov    %ebx,%eax
xor    %edx,%edx
div    %r14d
mov    %eax,%ebx
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %ebx,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd62(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [2 x i8] c"r\00"
@.str.1 = [22 x i8] c"Cannot open file %s \0A\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [3 x i8] c"%s\00"
@EOF = global i64 0
define i32 @nr_timesteps(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i16
%11 = alloca i64
%12 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%13 = load i32, i32* @BUFSIZ
%14 = add nsw i32 %13, 1
%15 = zext i32 %14 to i64
%16 = load i32, i32* @BUFSIZ
%17 = add nsw i32 %16, 1
%18 = zext i32 %17 to i64
%19 = call i8* @llvm.stacksave()
store i8* %19, i8** %8
%20 = alloca i8, i64 %18
store i64 %18, i64* %9
%21 = load i32, i32* %6
%22 = icmp ne i32 %21, 1
br i1 %22, label %23, label %32
23: ; preds = %3
%24 = load i8*, i8** %4
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %25, i32** %7
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %31
27: ; preds = %23
%28 = load i8*, i8** %4
%29 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %28)
%30 = call i32 @exit(i32 0)
unreachable
31: ; preds = %23
br label %41
32: ; preds = %3
%33 = load i8*, i8** %4
%34 = call i32* @fopen(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %34, i32** %7
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %40
36: ; preds = %32
%37 = load i8*, i8** %4
%38 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %37)
%39 = call i32 @exit(i32 0)
unreachable
40: ; preds = %32
br label %41
41: ; preds = %40, %31
store i64 0, i64* %11
%42 = load i32, i32* %6
%43 = icmp ne i32 %42, 1
br i1 %43, label %44, label %54
44: ; preds = %41
br label %45
45: ; preds = %50, %44
%46 = load i32*, i32** %7
%47 = call i64 @fscanf(i32* %46, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %20)
%48 = load i64, i64* @EOF
%49 = icmp ne i64 %47, %48
br i1 %49, label %50, label %53
50: ; preds = %45
%51 = load i64, i64* %11
%52 = add nsw i64 %51, 1
store i64 %52, i64* %11
br label %45
53: ; preds = %45
br label %66
54: ; preds = %41
br label %55
55: ; preds = %60, %54
%56 = load i32*, i32** %7
%57 = call i32 @feof(i32* %56)
%58 = icmp ne i32 %57, 0
%59 = xor i1 %58, true
br i1 %59, label %60, label %65
60: ; preds = %55
%61 = load i32*, i32** %7
%62 = call i32 @fread(i16* %10, i32 2, i32 1, i32* %61)
%63 = load i64, i64* %11
%64 = add nsw i64 %63, 1
store i64 %64, i64* %11
br label %55
65: ; preds = %55
br label %66
66: ; preds = %65, %53
%67 = load i64, i64* %11
%68 = load i32, i32* %5
%69 = sext i32 %68 to i64
%70 = sdiv i64 %67, %69
%71 = trunc i64 %70 to i32
store i32 %71, i32* %12
%72 = load i32*, i32** %7
%73 = call i32 @fclose(i32* %72)
%74 = load i32, i32* %12
%75 = load i8*, i8** %8
ret i32 %74
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [2 x i8] c"r\00"
@.str.1 = [22 x i8] c"Cannot open file %s \0A\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [3 x i8] c"%s\00"
@EOF = global i64 0
define i32 @nr_timesteps(i8* %0, i32 %1, i32 %2) {
%4 = alloca i16
%5 = load i32, i32* @BUFSIZ
%6 = add nsw i32 %5, 1
%7 = zext i32 %6 to i64
%8 = alloca i8, i64 %7
%9 = bitcast i16* %4 to i8*
%10 = icmp eq i32 %2, 1
br i1 %10, label %17, label %11
11: ; preds = %3
%12 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %26
14: ; preds = %11
%15 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%16 = tail call i32 @exit(i32 0)
unreachable
17: ; preds = %3
%18 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%22 = tail call i32 @exit(i32 0)
unreachable
23: ; preds = %17
%24 = tail call i32 @feof(i32* %18)
%25 = icmp eq i32 %24, 0
br i1 %25, label %32, label %38
26: ; preds = %11, %26
%27 = phi i64 [ %31, %26 ], [ 0, %11 ]
%28 = call i64 @fscanf(i32* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %8)
%29 = load i64, i64* @EOF
%30 = icmp eq i64 %28, %29
%31 = add nuw nsw i64 %27, 1
br i1 %30, label %38, label %26
32: ; preds = %23, %32
%33 = phi i64 [ %35, %32 ], [ 0, %23 ]
%34 = call i32 @fread(i16* %4, i32 2, i32 1, i32* %18)
%35 = add nuw nsw i64 %33, 1
%36 = tail call i32 @feof(i32* %18)
%37 = icmp eq i32 %36, 0
br i1 %37, label %32, label %38
38: ; preds = %26, %32, %23
%39 = phi i32* [ %18, %23 ], [ %18, %32 ], [ %12, %26 ]
%40 = phi i64 [ 0, %23 ], [ %35, %32 ], [ %27, %26 ]
%41 = sext i32 %1 to i64
%42 = sdiv i64 %40, %41
%43 = trunc i64 %42 to i32
%44 = call i32 @fclose(i32* %39)
ret i32 %43
}