#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*/ szBuffer;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
char *fgets(char *, int, int /*<<< orphan*/ *);
int strlen(char *);
int line_length(FILE *alignment_file_pointer) {
  char szBuffer[65536] = {0};
  char *pcRes = NULL;
  int length_of_line = 0;
  int total_length_of_line = 0;
  while ((pcRes = fgets(szBuffer, sizeof(szBuffer), alignment_file_pointer)) !=
         NULL) {
    length_of_line = strlen(szBuffer) - 1;
    total_length_of_line = total_length_of_line + length_of_line;
    if ((szBuffer)[length_of_line] == '\n') {
      break;
    }
  }
  return total_length_of_line;
}


x86 assembly (clang, -O0):
<line_length>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10020,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x10010(%rbp),%rdi
xor    %esi,%esi
mov    $0x10000,%edx
call   1040 <memset@plt>
movq   $0x0,-0x10018(%rbp)
movl   $0x0,-0x1001c(%rbp)
movl   $0x0,-0x10020(%rbp)
lea    -0x10010(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x10000,%esi
call   1050 <fgets@plt>
mov    %rax,-0x10018(%rbp)
cmp    $0x0,%rax
je     11e0 <line_length+0xb0>
lea    -0x10010(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x1001c(%rbp)
mov    -0x10020(%rbp),%eax
add    -0x1001c(%rbp),%eax
mov    %eax,-0x10020(%rbp)
movslq -0x1001c(%rbp),%rax
movsbl -0x10010(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    11db <line_length+0xab>
jmp    11e0 <line_length+0xb0>
jmp    1171 <line_length+0x41>
mov    -0x10020(%rbp),%eax
add    $0x10020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<line_length>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10000,%rsp
mov    %rdi,%r14
mov    %rsp,%rbx
xor    %ebp,%ebp
mov    $0x10000,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    $0x10000,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1191 <line_length+0x61>
mov    %rbx,%rdi
call   1030 <strlen@plt>
movslq %eax,%rcx
lea    -0x1(%rcx),%rax
add    %ebp,%eax
cmpb   $0xa,-0x1(%rsp,%rcx,1)
mov    %eax,%ebp
jne    1160 <line_length+0x30>
jmp    1193 <line_length+0x63>
mov    %ebp,%eax
add    $0x10000,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @line_length(i32* %0) {
%2 = alloca i32*
%3 = alloca [65536 x i8]
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %2
%7 = bitcast [65536 x i8]* %3 to i8*
store i8* null, i8** %4
store i32 0, i32* %5
store i32 0, i32* %6
br label %8
8: ; preds = %27, %1
%9 = getelementptr inbounds [65536 x i8], [65536 x i8]* %3, i64 0, i64 0
%10 = load i32*, i32** %2
%11 = call i8* @fgets(i8* %9, i32 65536, i32* %10)
store i8* %11, i8** %4
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %28
13: ; preds = %8
%14 = getelementptr inbounds [65536 x i8], [65536 x i8]* %3, i64 0, i64 0
%15 = call i32 @strlen(i8* %14)
%16 = sub nsw i32 %15, 1
store i32 %16, i32* %5
%17 = load i32, i32* %6
%18 = load i32, i32* %5
%19 = add nsw i32 %17, %18
store i32 %19, i32* %6
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [65536 x i8], [65536 x i8]* %3, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 10
br i1 %25, label %26, label %27
26: ; preds = %13
br label %28
27: ; preds = %13
br label %8
28: ; preds = %26, %8
%29 = load i32, i32* %6
ret i32 %29
}

LLVM IR (-O2):
define i32 @line_length(i32* nocapture %0) {
%2 = alloca [65536 x i8]
%3 = getelementptr inbounds [65536 x i8], [65536 x i8]* %2, i64 0, i64 0
br label %4
4: ; preds = %8, %1
%5 = phi i32 [ 0, %1 ], [ %11, %8 ]
%6 = call i8* @fgets(i8* %3, i32 65536, i32* %0)
%7 = icmp eq i8* %6, null
br i1 %7, label %16, label %8
8: ; preds = %4
%9 = call i32 @strlen(i8* %3)
%10 = add nsw i32 %9, -1
%11 = add nsw i32 %10, %5
%12 = sext i32 %10 to i64
%13 = getelementptr inbounds [65536 x i8], [65536 x i8]* %2, i64 0, i64 %12
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 10
br i1 %15, label %16, label %4
16: ; preds = %8, %4
%17 = phi i32 [ %11, %8 ], [ %5, %4 ]
ret i32 %17
}