#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 */
char EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int czytanie(char *nazwapliku) {
  int i = 0;
  char znak;
  FILE *baza = fopen(nazwapliku, "r");
  if (baza == NULL)
    printf("\n ZLE\n\n");
  while ((znak = getc(baza)) != EOF) {
    if (znak == '\n')
      i++;
  }
  fclose(baza);
  return i;
}


x86 assembly (clang, -O0):
<czytanie>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea2(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    117e <czytanie+0x3e>
lea    0xe89(%rip),%rdi
call   1040 <printf@plt>
jmp    1183 <czytanie+0x43>
mov    -0x18(%rbp),%rdi
call   1060 <getc@plt>
mov    %al,-0xd(%rbp)
movsbl %al,%eax
mov    0x2e4f(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11bf <czytanie+0x7f>
movsbl -0xd(%rbp),%eax
cmp    $0xa,%eax
jne    11ba <czytanie+0x7a>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1183 <czytanie+0x43>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<czytanie>:
push   %rbp
push   %r14
push   %rbx
lea    0xeb5(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1164 <czytanie+0x24>
lea    0xea3(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1060 <getc@plt>
mov    0x2e75(%rip),%r14
xor    %ebp,%ebp
cmp    (%r14),%al
je     1196 <czytanie+0x56>
xor    %ebp,%ebp
nopl   0x0(%rax)
xor    %ecx,%ecx
cmp    $0xa,%al
sete   %cl
add    %ecx,%ebp
mov    %rbx,%rdi
call   1060 <getc@plt>
cmp    (%r14),%al
jne    1180 <czytanie+0x40>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [8 x i8] c"\0A ZLE\0A\0A\00"
@EOF = global i8 0
define i32 @czytanie(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8
%5 = alloca i32*
store i8* %0, i8** %2
store i32 0, i32* %3
%6 = load i8*, i8** %2
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %5
%8 = load i32*, i32** %5
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %1
br label %13
13: ; preds = %27, %12
%14 = load i32*, i32** %5
%15 = call signext i8 @getc(i32* %14)
store i8 %15, i8* %4
%16 = sext i8 %15 to i32
%17 = load i8, i8* @EOF
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %16, %18
br i1 %19, label %20, label %28
20: ; preds = %13
%21 = load i8, i8* %4
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 10
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = load i32, i32* %3
%26 = add nsw i32 %25, 1
store i32 %26, i32* %3
br label %27
27: ; preds = %24, %20
br label %13
28: ; preds = %13
%29 = load i32*, i32** %5
%30 = call i32 @fclose(i32* %29)
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@EOF = global i8 0
@str = [7 x i8] c"\0A ZLE\0A\00"
define i32 @czytanie(i8* nocapture %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
br label %6
6: ; preds = %4, %1
%7 = tail call signext i8 @getc(i32* %2)
%8 = load i8, i8* @EOF
%9 = icmp eq i8 %7, %8
br i1 %9, label %19, label %10
10: ; preds = %6, %10
%11 = phi i8 [ %16, %10 ], [ %7, %6 ]
%12 = phi i32 [ %15, %10 ], [ 0, %6 ]
%13 = icmp eq i8 %11, 10
%14 = zext i1 %13 to i32
%15 = add nuw nsw i32 %12, %14
%16 = tail call signext i8 @getc(i32* %2)
%17 = load i8, i8* @EOF
%18 = icmp eq i8 %16, %17
br i1 %18, label %19, label %10
19: ; preds = %10, %6
%20 = phi i32 [ 0, %6 ], [ %15, %10 ]
%21 = tail call i32 @fclose(i32* %2)
ret i32 %20
}