#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 */
scalar_t__ EOF;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int nr_timesteps(char pp[400]) {
  FILE *fp1;
  char str1[20];
  long i;
  int r;
  printf("%s\n", pp);
  if ((fp1 = fopen(pp, "r")) == NULL) {
    printf("Cannot open file %s \n", pp);
    exit(0);
  }
  i = 0;
  while (fscanf(fp1, "%s", str1) != EOF)
    i++;
  r = (int)(i / (3));
  return r;
  fclose(fp1);
}


x86 assembly (clang, -O0):
<nr_timesteps>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xea9(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe9d(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1191 <nr_timesteps+0x51>
mov    -0x8(%rbp),%rsi
lea    0xe81(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>
movq   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rdx
lea    0xe74(%rip),%rsi
call   1040 <fscanf@plt>
mov    0x2e34(%rip),%rcx
cmp    (%rcx),%rax
je     11ce <nr_timesteps+0x8e>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    1199 <nr_timesteps+0x59>
mov    -0x38(%rbp),%rax
mov    $0x3,%ecx
cqto
idiv   %rcx
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nr_timesteps>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
lea    0xea9(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
lea    0xe9e(%rip),%rsi
mov    %rbx,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     11cc <nr_timesteps+0x8c>
mov    %rax,%r14
mov    $0xffffffffffffffff,%rbx
lea    0xe98(%rip),%r15
mov    %rsp,%r12
mov    0x2e5a(%rip),%r13
xchg   %ax,%ax
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1040 <fscanf@plt>
add    $0x1,%rbx
cmp    0x0(%r13),%rax
jne    1190 <nr_timesteps+0x50>
movabs $0xaaaaaaaaaaaaaaab,%rcx
aa aa aa
mov    %rbx,%rax
mul    %rcx
mov    %rdx,%rax
shr    %rax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xe33(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [22 x i8] c"Cannot open file %s \0A\00"
@.str.3 = [3 x i8] c"%s\00"
@EOF = global i64 0
define i32 @nr_timesteps(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca [20 x i8]
%5 = alloca i64
%6 = alloca i32
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = load i8*, i8** %2
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %3
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %16
12: ; preds = %1
%13 = load i8*, i8** %2
%14 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %13)
%15 = call i32 @exit(i32 0)
unreachable
16: ; preds = %1
store i64 0, i64* %5
br label %17
17: ; preds = %23, %16
%18 = load i32*, i32** %3
%19 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%20 = call i64 @fscanf(i32* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %19)
%21 = load i64, i64* @EOF
%22 = icmp ne i64 %20, %21
br i1 %22, label %23, label %26
23: ; preds = %17
%24 = load i64, i64* %5
%25 = add nsw i64 %24, 1
store i64 %25, i64* %5
br label %17
26: ; preds = %17
%27 = load i64, i64* %5
%28 = sdiv i64 %27, 3
%29 = trunc i64 %28 to i32
store i32 %29, i32* %6
%30 = load i32, i32* %6
ret i32 %30
}

LLVM IR (-O2):
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [22 x i8] c"Cannot open file %s \0A\00"
@.str.3 = [3 x i8] c"%s\00"
@EOF = global i64 0
define i32 @nr_timesteps(i8* %0) {
%2 = alloca [20 x i8]
%3 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %0)
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%9 = tail call i32 @exit(i32 0)
unreachable
10: ; preds = %1, %10
%11 = phi i64 [ %15, %10 ], [ 0, %1 ]
%12 = call i64 @fscanf(i32* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %3)
%13 = load i64, i64* @EOF
%14 = icmp eq i64 %12, %13
%15 = add nuw nsw i64 %11, 1
br i1 %14, label %16, label %10
16: ; preds = %10
%17 = udiv i64 %11, 3
%18 = trunc i64 %17 to i32
ret i32 %18
}