#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*/ EXIT_FAILURE;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
unsigned long mywc(const char *file_name) {
  unsigned long lines = 0;
  FILE *fp;
  char buf[4096];
  if ((fp = fopen(file_name, "r")) == NULL) {
    fprintf(stderr, "error: fopen %s\n%s\n", file_name, strerror(errno));
    exit(EXIT_FAILURE);
  }
  while (fgets(buf, 256, fp)) {
    lines++;
  }
  fclose(fp);
  return lines;
}


x86 assembly (clang, -O0):
<mywc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe7e(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11e7 <mywc+0x87>
mov    0x2e44(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x102c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x1028(%rbp)
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x102c(%rbp),%edi
mov    -0x1028(%rbp),%rdx
mov    %rax,%rcx
lea    0xe2e(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
jmp    11ec <mywc+0x8c>
lea    -0x1020(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x100,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     121c <mywc+0xbc>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11ec <mywc+0x8c>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mywc>:
push   %r15
push   %r14
push   %rbx
sub    $0x1000,%rsp
mov    %rdi,%r14
lea    0xe8a(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11c1 <mywc+0x61>
mov    %rax,%r15
mov    $0xffffffffffffffff,%rbx
mov    %rsp,%r14
nopl   (%rax)
mov    %r14,%rdi
mov    $0x100,%esi
mov    %r15,%rdx
call   1040 <fgets@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1190 <mywc+0x30>
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    %rbx,%rax
add    $0x1000,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2e18(%rip),%rax
mov    (%rax),%ebx
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe23(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
call   1050 <fprintf@plt>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [20 x i8] c"error: fopen %s\0A%s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define i64 @mywc(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i32*
%5 = alloca [4096 x i8]
store i8* %0, i8** %2
store i64 0, i64* %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** %4
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %17
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = load i8*, i8** %2
%12 = load i32, i32* @errno
%13 = call i8* @strerror(i32 %12)
%14 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %11, i8* %13)
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %1
br label %18
18: ; preds = %23, %17
%19 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%20 = load i32*, i32** %4
%21 = call i64 @fgets(i8* %19, i32 256, i32* %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = load i64, i64* %3
%25 = add i64 %24, 1
store i64 %25, i64* %3
br label %18
26: ; preds = %18
%27 = load i32*, i32** %4
%28 = call i32 @fclose(i32* %27)
%29 = load i64, i64* %3
ret i64 %29
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [20 x i8] c"error: fopen %s\0A%s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define i64 @mywc(i8* %0) {
%2 = alloca [4096 x i8]
%3 = getelementptr inbounds [4096 x i8], [4096 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 %6, label %13
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = load i32, i32* @errno
%9 = tail call i8* @strerror(i32 %8)
%10 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %9)
%11 = load i32, i32* @EXIT_FAILURE
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %1, %13
%14 = phi i64 [ %17, %13 ], [ 0, %1 ]
%15 = call i64 @fgets(i8* %3, i32 256, i32* %4)
%16 = icmp eq i64 %15, 0
%17 = add i64 %14, 1
br i1 %16, label %18, label %13
18: ; preds = %13
%19 = call i32 @fclose(i32* %4)
ret i64 %14
}