#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 */

/* Variables and functions */
int /*<<< orphan*/ LC_ALL;
scalar_t__ get_xtc_num_frames(char const *, int *, int *, float *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ setlocale(int /*<<< orphan*/, char *);
int /*<<< orphan*/ strcmp(char const *, char *);
int main(const int argc, const char *argv[]) {
  const char *help_text =
      "Count number of frames and simulation time of GROMACS XTC files\n"
      "Usage: xtc-length [-q] xtc [xtc]...\n\n"
      "Default behaviour is to provide running estimate of file length\n"
      "This can be suppressed using the '-q' flag\n";
  int i;
  bool quiet = false;
  int nframes, natoms;
  float psec;
  setlocale(LC_ALL, "");
  if (argc < 2 || !strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) {
    printf("%s", help_text);
    return 0;
  }
  if (argc >= 2 && !strcmp(argv[1], "-q"))
    quiet = true;
  for (i = quiet ? 2 : 1; i < argc; i++) {
    printf("%s\n", argv[i]);
    if (get_xtc_num_frames(argv[i], &nframes, &natoms, &psec, quiet)) {
      printf("ERROR: Error reading XTC file\n");
      return -1;
    }
    if (!quiet)
      printf("\r");
    printf("Trajectory contains %'d frames (%'.2f ns) of %'d atoms.\n\n",
           nframes, psec / 1000, natoms);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xea7(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
lea    0xfcb(%rip),%rsi
call   1060 <setlocale@plt>
cmpl   $0x2,-0x8(%rbp)
jl     11c1 <main+0x81>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xf3f(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
je     11c1 <main+0x81>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xf25(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11df <main+0x9f>
mov    -0x18(%rbp),%rsi
lea    0xf13(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12e4 <main+0x1a4>
cmpl   $0x2,-0x8(%rbp)
jl     120d <main+0xcd>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xeea(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    120d <main+0xcd>
movl   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%edx
mov    $0x1,%eax
mov    $0x2,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12dd <main+0x19d>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x20(%rbp),%r8d
lea    -0x24(%rbp),%rsi
lea    -0x28(%rbp),%rdx
lea    -0x2c(%rbp),%rcx
call   1030 <get_xtc_num_frames@plt>
cmp    $0x0,%rax
je     128e <main+0x14e>
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e4 <main+0x1a4>
cmpl   $0x0,-0x20(%rbp)
jne    12a6 <main+0x166>
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%esi
movss  -0x2c(%rbp),%xmm0
movss  0xd4a(%rip),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
mov    -0x28(%rbp),%edx
lea    0xe42(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1223 <main+0xe3>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%r12d
mov    0x2e65(%rip),%rax
mov    (%rax),%edi
lea    0xec6(%rip),%rsi
call   1080 <setlocale@plt>
cmp    $0x2,%r12d
jl     126b <main+0x10b>
mov    0x8(%rbx),%rbp
lea    0xe66(%rip),%rsi
mov    %rbp,%rdi
call   1070 <strcmp@plt>
test   %eax,%eax
je     126b <main+0x10b>
lea    0xe52(%rip),%rsi
mov    %rbp,%rdi
call   1070 <strcmp@plt>
test   %eax,%eax
je     126b <main+0x10b>
lea    0xe42(%rip),%rsi
mov    %rbp,%rdi
call   1070 <strcmp@plt>
mov    %eax,%r14d
xor    %r13d,%r13d
test   %eax,%eax
sete   %r13b
lea    0x1(%r13),%eax
xor    %r15d,%r15d
cmp    %r12d,%eax
jae    127a <main+0x11a>
mov    %eax,%ebp
mov    %r12d,%r12d
jmp    1231 <main+0xd1>
nopw   0x0(%rax,%rax,1)
mov    0x14(%rsp),%esi
movss  0xc(%rsp),%xmm0
divss  0xdee(%rip),%xmm0
cvtss2sd %xmm0,%xmm0
mov    0x10(%rsp),%edx
lea    0xdf0(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%r12
je     127a <main+0x11a>
mov    (%rbx,%rbp,8),%rdi
call   1040 <puts@plt>
mov    (%rbx,%rbp,8),%rdi
lea    0x14(%rsp),%rsi
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
mov    %r13d,%r8d
call   1050 <get_xtc_num_frames@plt>
test   %rax,%rax
jne    128c <main+0x12c>
test   %r14d,%r14d
je     1200 <main+0xa0>
mov    $0xd,%edi
call   1030 <putchar@plt>
jmp    1200 <main+0xa0>
lea    0xdd9(%rip),%rdi
call   1040 <puts@plt>
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe88(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%r15d
jmp    127a <main+0x11a>

LLVM IR (-O0):
@.str = [209 x i8] c"Count number of frames and simulation time of GROMACS XTC files\0AUsage: xtc-length [-q] xtc [xtc]...\0A\0ADefault behaviour is to provide running estimate of file length\0AThis can be suppressed using the '-q' flag\0A\00"
@LC_ALL = global i32 0
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [3 x i8] c"-h\00"
@.str.3 = [7 x i8] c"--help\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [3 x i8] c"-q\00"
@.str.6 = [4 x i8] c"%s\0A\00"
@.str.7 = [31 x i8] c"ERROR: Error reading XTC file\0A\00"
@.str.8 = [2 x i8] c"\0D\00"
@.str.9 = [58 x i8] c"Trajectory contains %'d frames (%'.2f ns) of %'d atoms.\0A\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca float
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([209 x i8], [209 x i8]* @.str, i64 0, i64 0), i8** %6
store i32 0, i32* %8
%12 = load i32, i32* @LC_ALL
%13 = call i32 @setlocale(i32 %12, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 2
br i1 %15, label %28, label %16
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @strcmp(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %16
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @strcmp(i8* %25, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%27 = icmp ne i32 %26, 0
br i1 %27, label %31, label %28
28: ; preds = %22, %16, %2
%29 = load i8*, i8** %6
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %29)
store i32 0, i32* %3
br label %83
31: ; preds = %22
%32 = load i32, i32* %4
%33 = icmp sge i32 %32, 2
br i1 %33, label %34, label %41
34: ; preds = %31
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = call i32 @strcmp(i8* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%39 = icmp ne i32 %38, 0
br i1 %39, label %41, label %40
40: ; preds = %34
store i32 1, i32* %8
br label %41
41: ; preds = %40, %34, %31
%42 = load i32, i32* %8
%43 = icmp ne i32 %42, 0
%44 = zext i1 %43 to i64
%45 = select i1 %43, i32 2, i32 1
store i32 %45, i32* %7
br label %46
46: ; preds = %79, %41
%47 = load i32, i32* %7
%48 = load i32, i32* %4
%49 = icmp slt i32 %47, %48
br i1 %49, label %50, label %82
50: ; preds = %46
%51 = load i8**, i8*** %5
%52 = load i32, i32* %7
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8*, i8** %51, i64 %53
%55 = load i8*, i8** %54
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %55)
%57 = load i8**, i8*** %5
%58 = load i32, i32* %7
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8*, i8** %57, i64 %59
%61 = load i8*, i8** %60
%62 = load i32, i32* %8
%63 = call i64 @get_xtc_num_frames(i8* %61, i32* %9, i32* %10, float* %11, i32 %62)
%64 = icmp ne i64 %63, 0
br i1 %64, label %65, label %67
65: ; preds = %50
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0))
store i32 -1, i32* %3
br label %83
67: ; preds = %50
%68 = load i32, i32* %8
%69 = icmp ne i32 %68, 0
br i1 %69, label %72, label %70
70: ; preds = %67
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
br label %72
72: ; preds = %70, %67
%73 = load i32, i32* %9
%74 = load float, float* %11
%75 = fdiv float %74, 1.000000e+03
%76 = fpext float %75 to double
%77 = load i32, i32* %10
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.9, i64 0, i64 0), i32 %73, double %76, i32 %77)
br label %79
79: ; preds = %72
%80 = load i32, i32* %7
%81 = add nsw i32 %80, 1
store i32 %81, i32* %7
br label %46
82: ; preds = %46
store i32 0, i32* %3
br label %83
83: ; preds = %82, %65, %28
%84 = load i32, i32* %3
ret i32 %84
}

LLVM IR (-O2):
@LC_ALL = global i32 0
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [3 x i8] c"-h\00"
@.str.3 = [7 x i8] c"--help\00"
@.str.5 = [3 x i8] c"-q\00"
@.str.9 = [58 x i8] c"Trajectory contains %'d frames (%'.2f ns) of %'d atoms.\0A\0A\00"
@str = [208 x i8] c"Count number of frames and simulation time of GROMACS XTC files\0AUsage: xtc-length [-q] xtc [xtc]...\0A\0ADefault behaviour is to provide running estimate of file length\0AThis can be suppressed using the '-q' flag\00"
@str.10 = [30 x i8] c"ERROR: Error reading XTC file\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca float
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = bitcast float* %5 to i8*
%9 = load i32, i32* @LC_ALL
%10 = tail call i32 @setlocale(i32 %9, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp slt i32 %0, 2
br i1 %11, label %20, label %12
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i32 @strcmp(i8* dereferenceable(1) %14, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp eq i32 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %12
%18 = tail call i32 @strcmp(i8* dereferenceable(1) %14, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17, %12, %2
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([208 x i8], [208 x i8]* @str, i64 0, i64 0))
br label %53
22: ; preds = %17
%23 = tail call i32 @strcmp(i8* dereferenceable(1) %14, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%24 = icmp eq i32 %23, 0
%25 = select i1 %24, i32 2, i32 1
%26 = zext i1 %24 to i32
%27 = icmp ult i32 %25, %0
br i1 %27, label %28, label %53
28: ; preds = %22
%29 = zext i32 %25 to i64
%30 = zext i32 %0 to i64
br label %31
31: ; preds = %28, %44
%32 = phi i64 [ %29, %28 ], [ %51, %44 ]
%33 = getelementptr inbounds i8*, i8** %1, i64 %32
%34 = load i8*, i8** %33
%35 = call i32 @puts(i8* dereferenceable(1) %34)
%36 = load i8*, i8** %33
%37 = call i64 @get_xtc_num_frames(i8* %36, i32* %3, i32* %4, float* %5, i32 %26)
%38 = icmp eq i64 %37, 0
br i1 %38, label %41, label %39
39: ; preds = %31
%40 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.10, i64 0, i64 0))
br label %53
41: ; preds = %31
br i1 %24, label %44, label %42
42: ; preds = %41
%43 = call i32 @putchar(i32 13)
br label %44
44: ; preds = %42, %41
%45 = load i32, i32* %3
%46 = load float, float* %5
%47 = fdiv float %46, 1.000000e+03
%48 = fpext float %47 to double
%49 = load i32, i32* %4
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @.str.9, i64 0, i64 0), i32 %45, double %48, i32 %49)
%51 = add nuw nsw i64 %32, 1
%52 = icmp eq i64 %51, %30
br i1 %52, label %53, label %31
53: ; preds = %44, %22, %39, %20
%54 = phi i32 [ 0, %20 ], [ -1, %39 ], [ 0, %22 ], [ 0, %44 ]
ret i32 %54
}