#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*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
void countLinesInFile(char *fileName, int *target) {
  FILE *file = NULL;
  char buffer[256] = "\0";
  file = fopen(fileName, "r");
  if (file == NULL) {
    printf("ERROR!!!\nFile reading failed!\n");
    target = NULL;
    return;
  }
  while (!feof(file)) {
    strcpy(buffer, "\0");
    fgets(buffer, 255, file);
    if (strlen(buffer) != 0 && strcmp(buffer, "\n") != 0)
      (*target)++;
  }
  fclose(file);
}


x86 assembly (clang, -O0):
<countLinesInFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1070 <memset@plt>
mov    -0x8(%rbp),%rdi
lea    0xe37(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11f6 <countLinesInFile+0x66>
lea    0xe1e(%rip),%rdi
call   1060 <printf@plt>
movq   $0x0,-0x10(%rbp)
jmp    128d <countLinesInFile+0xfd>
jmp    11fb <countLinesInFile+0x6b>
mov    -0x18(%rbp),%rdi
call   10a0 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1219 <countLinesInFile+0x89>
jmp    1284 <countLinesInFile+0xf4>
lea    -0x120(%rbp),%rdi
lea    0xdfa(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0xff,%esi
call   1080 <fgets@plt>
lea    -0x120(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x0,%rax
je     127f <countLinesInFile+0xef>
lea    -0x120(%rbp),%rdi
lea    0xdba(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
je     127f <countLinesInFile+0xef>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
jmp    11fb <countLinesInFile+0x6b>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<countLinesInFile>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x100,%rsp
mov    %rsi,%r14
xorps  %xmm0,%xmm0
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
lea    0xe0c(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1226 <countLinesInFile+0xb6>
mov    %rax,%rbx
mov    %rax,%rdi
call   1080 <feof@plt>
test   %eax,%eax
je     1242 <countLinesInFile+0xd2>
mov    %rbx,%rdi
call   1050 <fclose@plt>
add    $0x100,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xdd7(%rip),%rdi
add    $0x100,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1040 <puts@plt>
lea    0xdd9(%rip),%r15
mov    %rsp,%r12
lea    0xdaf(%rip),%r13
jmp    126c <countLinesInFile+0xfc>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
call   1080 <feof@plt>
test   %eax,%eax
jne    120d <countLinesInFile+0x9d>
mov    %r12,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %r12,%rdi
mov    $0xff,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
cmpb   $0x0,(%rsp)
je     1260 <countLinesInFile+0xf0>
mov    %r12,%rdi
mov    %r13,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1260 <countLinesInFile+0xf0>
addl   $0x1,(%r14)
jmp    1260 <countLinesInFile+0xf0>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [31 x i8] c"ERROR!!!\0AFile reading failed!\0A\00"
@.str.2 = [2 x i8] zeroinitializer
@.str.3 = [2 x i8] c"\0A\00"
define void @countLinesInFile(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca [256 x i8]
store i8* %0, i8** %3
store i32* %1, i32** %4
store i32* null, i32** %5
%7 = bitcast [256 x i8]* %6 to i8*
%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** %5
%10 = load i32*, i32** %5
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
store i32* null, i32** %4
br label %41
14: ; preds = %2
br label %15
15: ; preds = %37, %14
%16 = load i32*, i32** %5
%17 = call i32 @feof(i32* %16)
%18 = icmp ne i32 %17, 0
%19 = xor i1 %18, true
br i1 %19, label %20, label %38
20: ; preds = %15
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%22 = call i32 @strcpy(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%24 = load i32*, i32** %5
%25 = call i32 @fgets(i8* %23, i32 255, i32* %24)
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%27 = call i64 @strlen(i8* %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %37
29: ; preds = %20
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%31 = call i64 @strcmp(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %29
%34 = load i32*, i32** %4
%35 = load i32, i32* %34
%36 = add nsw i32 %35, 1
store i32 %36, i32* %34
br label %37
37: ; preds = %33, %29, %20
br label %15
38: ; preds = %15
%39 = load i32*, i32** %5
%40 = call i32 @fclose(i32* %39)
br label %41
41: ; preds = %38, %12
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.2 = [2 x i8] zeroinitializer
@.str.3 = [2 x i8] c"\0A\00"
@str = [30 x i8] c"ERROR!!!\0AFile reading failed!\00"
define void @countLinesInFile(i8* nocapture %0, i32* nocapture %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = call i32 @feof(i32* %5)
%9 = icmp eq i32 %8, 0
br i1 %9, label %12, label %26
10: ; preds = %2
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
br label %28
12: ; preds = %7, %23
%13 = call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 @fgets(i8* %4, i32 255, i32* %5)
%15 = load i8, i8* %4
%16 = icmp eq i8 %15, 0
br i1 %16, label %23, label %17
17: ; preds = %12
%18 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %17
%21 = load i32, i32* %1
%22 = add nsw i32 %21, 1
store i32 %22, i32* %1
br label %23
23: ; preds = %20, %17, %12
%24 = call i32 @feof(i32* %5)
%25 = icmp eq i32 %24, 0
br i1 %25, label %12, label %26
26: ; preds = %23, %7
%27 = call i32 @fclose(i32* %5)
br label %28
28: ; preds = %26, %10
ret void
}