#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ nrerror(char *);
int sscanf(char *, char *, double *, double *, double *);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
long read_pdb_ref(char *pdbfile, char **sAtomName, double **sxyz) {
  char str[512], temp[512];
  long n = 0;
  FILE *fp;
  if ((fp = fopen(pdbfile, "r")) == NULL) {
    return 0;
  }
  while (fgets(str, sizeof str, fp) != NULL) {
    if (strncmp(str, "ATOM", 4))
      continue;
    n++;
    strncpy(sAtomName[n], str + 12, 4);
    sAtomName[n][4] = '\0';
    strncpy(temp, str + 30, 25);
    temp[25] = '\0';
    if (sscanf(temp, "%8lf%8lf%8lf", &sxyz[n][1], &sxyz[n][2], &sxyz[n][3]) !=
        3)
      nrerror("error reading xyz-coordinate");
  }
  fclose(fp);
  return n;
}


x86 assembly (clang, -O0):
<read_pdb_ref>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x428(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe63(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x430(%rbp)
cmp    $0x0,%rax
jne    11c0 <read_pdb_ref+0x50>
movq   $0x0,-0x8(%rbp)
jmp    12f7 <read_pdb_ref+0x187>
jmp    11c5 <read_pdb_ref+0x55>
lea    -0x220(%rbp),%rdi
mov    -0x430(%rbp),%rdx
mov    $0x200,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     12e0 <read_pdb_ref+0x170>
lea    -0x220(%rbp),%rdi
lea    0xe0d(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
je     120e <read_pdb_ref+0x9e>
jmp    11c5 <read_pdb_ref+0x55>
mov    -0x428(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x428(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x428(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x220(%rbp),%rsi
add    $0xc,%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
mov    -0x428(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movb   $0x0,0x4(%rax)
lea    -0x420(%rbp),%rdi
lea    -0x220(%rbp),%rsi
add    $0x1e,%rsi
mov    $0x19,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x407(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    -0x428(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
add    $0x8,%rdx
mov    -0x20(%rbp),%rax
mov    -0x428(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
add    $0x10,%rcx
mov    -0x20(%rbp),%rax
mov    -0x428(%rbp),%rsi
mov    (%rax,%rsi,8),%r8
add    $0x18,%r8
lea    0xd46(%rip),%rsi
call   1080 <sscanf@plt>
cmp    $0x3,%eax
je     12db <read_pdb_ref+0x16b>
lea    0xd3e(%rip),%rdi
call   1050 <nrerror@plt>
jmp    11c5 <read_pdb_ref+0x55>
mov    -0x430(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x428(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_pdb_ref>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %rdx,0x8(%rsp)
mov    %rsi,%r15
lea    0xe70(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     127e <read_pdb_ref+0x10e>
mov    %rax,%rbx
xor    %r13d,%r13d
lea    0x10(%rsp),%rbp
lea    0xe52(%rip),%r12
mov    %rbp,%rdi
mov    $0x200,%esi
mov    %rbx,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1274 <read_pdb_ref+0x104>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
jne    11b0 <read_pdb_ref+0x40>
lea    0x1(%r13),%rax
mov    %rax,(%rsp)
mov    0x8(%r15,%r13,8),%rdi
lea    0x1c(%rsp),%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
mov    0x8(%r15,%r13,8),%rax
movb   $0x0,0x4(%rax)
mov    %r15,%r14
lea    0x210(%rsp),%r15
mov    %r15,%rdi
lea    0x2e(%rsp),%rsi
mov    $0x19,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x229(%rsp)
mov    0x8(%rsp),%rax
mov    0x8(%rax,%r13,8),%r8
lea    0x8(%r8),%rdx
lea    0x10(%r8),%rcx
add    $0x18,%r8
mov    %r15,%rdi
mov    %r14,%r15
mov    (%rsp),%r14
lea    0xdb8(%rip),%rsi
call   1080 <sscanf@plt>
mov    %r14,%r13
cmp    $0x3,%eax
je     11b0 <read_pdb_ref+0x40>
lea    0xdad(%rip),%rdi
call   1050 <nrerror@plt>
mov    %r14,%r13
jmp    11b0 <read_pdb_ref+0x40>
mov    %rbx,%rdi
call   1060 <fclose@plt>
jmp    1281 <read_pdb_ref+0x111>
xor    %r13d,%r13d
mov    %r13,%rax
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [5 x i8] c"ATOM\00"
@.str.2 = [13 x i8] c"%8lf%8lf%8lf\00"
@.str.3 = [29 x i8] c"error reading xyz-coordinate\00"
define i64 @read_pdb_ref(i8* %0, i8** %1, double** %2) {
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca double**
%8 = alloca [512 x i8]
%9 = alloca [512 x i8]
%10 = alloca i64
%11 = alloca i32*
store i8* %0, i8** %5
store i8** %1, i8*** %6
store double** %2, double*** %7
store i64 0, i64* %10
%12 = load i8*, i8** %5
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %11
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %16
15: ; preds = %3
store i64 0, i64* %4
br label %72
16: ; preds = %3
br label %17
17: ; preds = %67, %26, %16
%18 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%19 = load i32*, i32** %11
%20 = call i32* @fgets(i8* %18, i32 512, i32* %19)
%21 = icmp ne i32* %20, null
br i1 %21, label %22, label %68
22: ; preds = %17
%23 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%24 = call i64 @strncmp(i8* %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %22
br label %17
27: ; preds = %22
%28 = load i64, i64* %10
%29 = add nsw i64 %28, 1
store i64 %29, i64* %10
%30 = load i8**, i8*** %6
%31 = load i64, i64* %10
%32 = getelementptr inbounds i8*, i8** %30, i64 %31
%33 = load i8*, i8** %32
%34 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%35 = getelementptr inbounds i8, i8* %34, i64 12
%36 = call i32 @strncpy(i8* %33, i8* %35, i32 4)
%37 = load i8**, i8*** %6
%38 = load i64, i64* %10
%39 = getelementptr inbounds i8*, i8** %37, i64 %38
%40 = load i8*, i8** %39
%41 = getelementptr inbounds i8, i8* %40, i64 4
store i8 0, i8* %41
%42 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%43 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%44 = getelementptr inbounds i8, i8* %43, i64 30
%45 = call i32 @strncpy(i8* %42, i8* %44, i32 25)
%46 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 25
store i8 0, i8* %46
%47 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%48 = load double**, double*** %7
%49 = load i64, i64* %10
%50 = getelementptr inbounds double*, double** %48, i64 %49
%51 = load double*, double** %50
%52 = getelementptr inbounds double, double* %51, i64 1
%53 = load double**, double*** %7
%54 = load i64, i64* %10
%55 = getelementptr inbounds double*, double** %53, i64 %54
%56 = load double*, double** %55
%57 = getelementptr inbounds double, double* %56, i64 2
%58 = load double**, double*** %7
%59 = load i64, i64* %10
%60 = getelementptr inbounds double*, double** %58, i64 %59
%61 = load double*, double** %60
%62 = getelementptr inbounds double, double* %61, i64 3
%63 = call i32 @sscanf(i8* %47, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), double* %52, double* %57, double* %62)
%64 = icmp ne i32 %63, 3
br i1 %64, label %65, label %67
65: ; preds = %27
%66 = call i32 @nrerror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
br label %67
67: ; preds = %65, %27
br label %17
68: ; preds = %17
%69 = load i32*, i32** %11
%70 = call i32 @fclose(i32* %69)
%71 = load i64, i64* %10
store i64 %71, i64* %4
br label %72
72: ; preds = %68, %15
%73 = load i64, i64* %4
ret i64 %73
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [5 x i8] c"ATOM\00"
@.str.2 = [13 x i8] c"%8lf%8lf%8lf\00"
@.str.3 = [29 x i8] c"error reading xyz-coordinate\00"
define i64 @read_pdb_ref(i8* nocapture %0, i8** nocapture %1, double** nocapture %2) {
%4 = alloca [512 x i8]
%5 = alloca [512 x i8]
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%8 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %42, label %10
10: ; preds = %3
%11 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 12
%12 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 30
%13 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 25
br label %14
14: ; preds = %39, %10
%15 = phi i64 [ 0, %10 ], [ %23, %39 ]
br label %16
16: ; preds = %14, %19
%17 = call i32* @fgets(i8* %6, i32 512, i32* %8)
%18 = icmp eq i32* %17, null
br i1 %18, label %40, label %19
19: ; preds = %16
%20 = call i64 @strncmp(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %16
22: ; preds = %19
%23 = add nuw nsw i64 %15, 1
%24 = getelementptr inbounds i8*, i8** %1, i64 %23
%25 = load i8*, i8** %24
%26 = call i32 @strncpy(i8* %25, i8* %11, i32 4)
%27 = load i8*, i8** %24
%28 = getelementptr inbounds i8, i8* %27, i64 4
store i8 0, i8* %28
%29 = call i32 @strncpy(i8* %7, i8* %12, i32 25)
store i8 0, i8* %13
%30 = getelementptr inbounds double*, double** %2, i64 %23
%31 = load double*, double** %30
%32 = getelementptr inbounds double, double* %31, i64 1
%33 = getelementptr inbounds double, double* %31, i64 2
%34 = getelementptr inbounds double, double* %31, i64 3
%35 = call i32 @sscanf(i8* %7, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), double* %32, double* %33, double* %34)
%36 = icmp eq i32 %35, 3
br i1 %36, label %39, label %37
37: ; preds = %22
%38 = call i32 @nrerror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
br label %39
39: ; preds = %37, %22
br label %14
40: ; preds = %16
%41 = call i32 @fclose(i32* %8)
br label %42
42: ; preds = %3, %40
%43 = phi i64 [ %15, %40 ], [ 0, %3 ]
ret i64 %43
}