#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*/ strncmp(char *, char *, int);
long upperstr(char *);
long number_of_atoms(char *pdbfile) {
  char str[512];
  long n = 0, nlen;
  FILE *fp;
  if ((fp = fopen(pdbfile, "r")) == NULL) {
    return 0;
  }
  while (fgets(str, sizeof str, fp) != NULL) {
    nlen = upperstr(str);
    if (!strncmp(str + 17, "HOH", 3) || !strncmp(str + 17, "WAT", 3))
      continue;
    if (str[13] == 'H')
      continue;
    if (nlen >= 54 && !strncmp(str, "ATOM", 4) || (!strncmp(str, "HETATM", 6)))
      n++;
  }
  fclose(fp);
  return n;
}


x86 assembly (clang, -O0):
<number_of_atoms>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x218(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe8b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x228(%rbp)
cmp    $0x0,%rax
jne    1198 <number_of_atoms+0x48>
movq   $0x0,-0x8(%rbp)
jmp    12b4 <number_of_atoms+0x164>
jmp    119d <number_of_atoms+0x4d>
lea    -0x210(%rbp),%rdi
mov    -0x228(%rbp),%rdx
mov    $0x200,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     129d <number_of_atoms+0x14d>
lea    -0x210(%rbp),%rdi
call   1060 <upperstr@plt>
mov    %rax,-0x220(%rbp)
lea    -0x210(%rbp),%rdi
add    $0x11,%rdi
lea    0xe1e(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
je     121c <number_of_atoms+0xcc>
lea    -0x210(%rbp),%rdi
add    $0x11,%rdi
lea    0xdfd(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1221 <number_of_atoms+0xd1>
jmp    119d <number_of_atoms+0x4d>
movsbl -0x203(%rbp),%eax
cmp    $0x48,%eax
jne    1236 <number_of_atoms+0xe6>
jmp    119d <number_of_atoms+0x4d>
cmpq   $0x36,-0x220(%rbp)
36
jl     1265 <number_of_atoms+0x115>
lea    -0x210(%rbp),%rdi
lea    0xdb8(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
je     1286 <number_of_atoms+0x136>
lea    -0x210(%rbp),%rdi
lea    0xd9c(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1298 <number_of_atoms+0x148>
mov    -0x218(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x218(%rbp)
jmp    119d <number_of_atoms+0x4d>
mov    -0x228(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x218(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<number_of_atoms>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x208,%rsp
lea    0xe98(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     119d <number_of_atoms+0x4d>
mov    %rax,%r12
mov    %rsp,%rdi
mov    $0x200,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11a1 <number_of_atoms+0x51>
lea    0x11(%rsp),%r15
xor    %ebp,%ebp
mov    %rsp,%rbx
lea    0xe67(%rip),%r13
jmp    11e5 <number_of_atoms+0x95>
xor    %ebp,%ebp
jmp    11ab <number_of_atoms+0x5b>
xor    %ebp,%ebp
mov    %r12,%rdi
call   1040 <fclose@plt>
mov    %rbp,%rax
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
add    $0x1,%rbp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
mov    $0x200,%esi
mov    %r12,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11a3 <number_of_atoms+0x53>
mov    %rbx,%rdi
call   1060 <upperstr@plt>
mov    %rax,%r14
mov    %r15,%rdi
mov    %r13,%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     11d0 <number_of_atoms+0x80>
mov    %r15,%rdi
lea    0xdf8(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     11d0 <number_of_atoms+0x80>
cmpb   $0x48,0xd(%rsp)
je     11d0 <number_of_atoms+0x80>
cmp    $0x36,%r14
jl     1245 <number_of_atoms+0xf5>
mov    %rbx,%rdi
lea    0xdd7(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     11c0 <number_of_atoms+0x70>
mov    %rbx,%rdi
lea    0xdc0(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    11d0 <number_of_atoms+0x80>
jmp    11c0 <number_of_atoms+0x70>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [4 x i8] c"HOH\00"
@.str.2 = [4 x i8] c"WAT\00"
@.str.3 = [5 x i8] c"ATOM\00"
@.str.4 = [7 x i8] c"HETATM\00"
define i64 @number_of_atoms(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca [512 x i8]
%5 = alloca i64
%6 = alloca i64
%7 = alloca i32*
store i8* %0, i8** %3
store i64 0, i64* %5
%8 = load i8*, i8** %3
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %7
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %12
11: ; preds = %1
store i64 0, i64* %2
br label %56
12: ; preds = %1
br label %13
13: ; preds = %51, %36, %30, %12
%14 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%15 = load i32*, i32** %7
%16 = call i32* @fgets(i8* %14, i32 512, i32* %15)
%17 = icmp ne i32* %16, null
br i1 %17, label %18, label %52
18: ; preds = %13
%19 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%20 = call i64 @upperstr(i8* %19)
store i64 %20, i64* %6
%21 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%22 = getelementptr inbounds i8, i8* %21, i64 17
%23 = call i32 @strncmp(i8* %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %18
%26 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%27 = getelementptr inbounds i8, i8* %26, i64 17
%28 = call i32 @strncmp(i8* %27, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 3)
%29 = icmp ne i32 %28, 0
br i1 %29, label %31, label %30
30: ; preds = %25, %18
br label %13
31: ; preds = %25
%32 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 13
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 72
br i1 %35, label %36, label %37
36: ; preds = %31
br label %13
37: ; preds = %31
%38 = load i64, i64* %6
%39 = icmp sge i64 %38, 54
br i1 %39, label %40, label %44
40: ; preds = %37
%41 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%42 = call i32 @strncmp(i8* %41, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %48
44: ; preds = %40, %37
%45 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%46 = call i32 @strncmp(i8* %45, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 6)
%47 = icmp ne i32 %46, 0
br i1 %47, label %51, label %48
48: ; preds = %44, %40
%49 = load i64, i64* %5
%50 = add nsw i64 %49, 1
store i64 %50, i64* %5
br label %51
51: ; preds = %48, %44
br label %13
52: ; preds = %13
%53 = load i32*, i32** %7
%54 = call i32 @fclose(i32* %53)
%55 = load i64, i64* %5
store i64 %55, i64* %2
br label %56
56: ; preds = %52, %11
%57 = load i64, i64* %2
ret i64 %57
}

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