#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ printf(char *);
void read_amber_coor(char *label, long n, double *x, double *y, double *z) {
  long i, na;
  char line_buf[200];
  FILE *fp;
  fp = fopen(label, "rt");
  if (fp == NULL) {
    printf("** E ** cannot read coor file\n");
    exit(0);
  }
  fgets(line_buf, 82, fp);
  fscanf(fp, "%li", &na);
  if (n != na) {
    printf("Number of atoms does not match prmtop\n");
    exit(0);
  }
  for (i = 0; i < n; i++)
    fscanf(fp, "%lf%lf%lf", &x[i], &y[i], &z[i]);
  fclose(fp);
}


x86 assembly (clang, -O0):
<read_amber_coor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe76(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x108(%rbp)
cmpq   $0x0,-0x108(%rbp)
jne    11b7 <read_amber_coor+0x57>
lea    0xe58(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
lea    -0x100(%rbp),%rdi
mov    -0x108(%rbp),%rdx
mov    $0x52,%esi
call   1060 <fgets@plt>
mov    -0x108(%rbp),%rdi
lea    0xe45(%rip),%rsi
lea    -0x38(%rbp),%rdx
mov    $0x0,%al
call   1050 <fscanf@plt>
mov    -0x10(%rbp),%rax
cmp    -0x38(%rbp),%rax
je     1209 <read_amber_coor+0xa9>
lea    0xe29(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x10(%rbp),%rax
jge    1272 <read_amber_coor+0x112>
mov    -0x108(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x30(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdx
mov    -0x20(%rbp),%rcx
mov    -0x30(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rcx
mov    -0x28(%rbp),%r8
mov    -0x30(%rbp),%rax
shl    $0x3,%rax
add    %rax,%r8
lea    0xdf3(%rip),%rsi
mov    $0x0,%al
call   1050 <fscanf@plt>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1211 <read_amber_coor+0xb1>
mov    -0x108(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_amber_coor>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xd8,%rsp
mov    %r8,%r14
mov    %rcx,%r15
mov    %rdx,%rbx
mov    %rsi,%r12
lea    0xe7c(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1212 <read_amber_coor+0xb2>
mov    %rax,%r13
lea    0x10(%rsp),%rdi
mov    $0x52,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
lea    0xe55(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %r13,%rdi
xor    %eax,%eax
call   1050 <fscanf@plt>
cmp    %r12,0x8(%rsp)
jne    121b <read_amber_coor+0xbb>
test   %r12,%r12
jle    11f8 <read_amber_coor+0x98>
lea    0xe37(%rip),%rbp
mov    %r13,%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
mov    %r15,%rcx
mov    %r14,%r8
xor    %eax,%eax
call   1050 <fscanf@plt>
add    $0x8,%r14
add    $0x8,%r15
add    $0x8,%rbx
add    $0xffffffffffffffff,%r12
jne    11d0 <read_amber_coor+0x70>
mov    %r13,%rdi
call   1040 <fclose@plt>
add    $0xd8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe1e(%rip),%rdi
jmp    1222 <read_amber_coor+0xc2>
lea    0xdef(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"rt\00"
@.str.1 = [31 x i8] c"** E ** cannot read coor file\0A\00"
@.str.2 = [4 x i8] c"%li\00"
@.str.3 = [39 x i8] c"Number of atoms does not match prmtop\0A\00"
@.str.4 = [10 x i8] c"%lf%lf%lf\00"
define void @read_amber_coor(i8* %0, i64 %1, double* %2, double* %3, double* %4) {
%6 = alloca i8*
%7 = alloca i64
%8 = alloca double*
%9 = alloca double*
%10 = alloca double*
%11 = alloca i64
%12 = alloca i64
%13 = alloca [200 x i8]
%14 = alloca i32*
store i8* %0, i8** %6
store i64 %1, i64* %7
store double* %2, double** %8
store double* %3, double** %9
store double* %4, double** %10
%15 = load i8*, i8** %6
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %14
%17 = load i32*, i32** %14
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %22
19: ; preds = %5
%20 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @exit(i32 0)
unreachable
22: ; preds = %5
%23 = getelementptr inbounds [200 x i8], [200 x i8]* %13, i64 0, i64 0
%24 = load i32*, i32** %14
%25 = call i32 @fgets(i8* %23, i32 82, i32* %24)
%26 = load i32*, i32** %14
%27 = call i32 (i32*, i8*, ...) @fscanf(i32* %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64* %12)
%28 = load i64, i64* %7
%29 = load i64, i64* %12
%30 = icmp ne i64 %28, %29
br i1 %30, label %31, label %34
31: ; preds = %22
%32 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0))
%33 = call i32 @exit(i32 0)
unreachable
34: ; preds = %22
store i64 0, i64* %11
br label %35
35: ; preds = %51, %34
%36 = load i64, i64* %11
%37 = load i64, i64* %7
%38 = icmp slt i64 %36, %37
br i1 %38, label %39, label %54
39: ; preds = %35
%40 = load i32*, i32** %14
%41 = load double*, double** %8
%42 = load i64, i64* %11
%43 = getelementptr inbounds double, double* %41, i64 %42
%44 = load double*, double** %9
%45 = load i64, i64* %11
%46 = getelementptr inbounds double, double* %44, i64 %45
%47 = load double*, double** %10
%48 = load i64, i64* %11
%49 = getelementptr inbounds double, double* %47, i64 %48
%50 = call i32 (i32*, i8*, ...) @fscanf(i32* %40, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), double* %43, double* %46, double* %49)
br label %51
51: ; preds = %39
%52 = load i64, i64* %11
%53 = add nsw i64 %52, 1
store i64 %53, i64* %11
br label %35
54: ; preds = %35
%55 = load i32*, i32** %14
%56 = call i32 @fclose(i32* %55)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"rt\00"
@.str.2 = [4 x i8] c"%li\00"
@.str.4 = [10 x i8] c"%lf%lf%lf\00"
@str = [38 x i8] c"Number of atoms does not match prmtop\00"
@str.5 = [30 x i8] c"** E ** cannot read coor file\00"
define void @read_amber_coor(i8* nocapture %0, i64 %1, double* %2, double* %3, double* %4) {
%6 = alloca i64
%7 = alloca [200 x i8]
%8 = bitcast i64* %6 to i8*
%9 = getelementptr inbounds [200 x i8], [200 x i8]* %7, i64 0, i64 0
%10 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %15
12: ; preds = %5
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.5, i64 0, i64 0))
%14 = tail call i32 @exit(i32 0)
unreachable
15: ; preds = %5
%16 = call i32 @fgets(i8* %9, i32 82, i32* %10)
%17 = call i32 (i32*, i8*, ...) @fscanf(i32* %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64* %6)
%18 = load i64, i64* %6
%19 = icmp eq i64 %18, %1
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = icmp sgt i64 %1, 0
br i1 %21, label %25, label %33
22: ; preds = %15
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
%24 = call i32 @exit(i32 0)
unreachable
25: ; preds = %20, %25
%26 = phi i64 [ %31, %25 ], [ 0, %20 ]
%27 = getelementptr inbounds double, double* %2, i64 %26
%28 = getelementptr inbounds double, double* %3, i64 %26
%29 = getelementptr inbounds double, double* %4, i64 %26
%30 = call i32 (i32*, i8*, ...) @fscanf(i32* %10, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), double* %27, double* %28, double* %29)
%31 = add nuw nsw i64 %26, 1
%32 = icmp eq i64 %31, %1
br i1 %32, label %33, label %25
33: ; preds = %25, %20
%34 = call i32 @fclose(i32* %10)
ret void
}