#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 EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int getProgramSize(char *filename, int *w, int *h) {
  FILE *fp = fopen(filename, "r");
  int i, j, k, c;
  i = 0;
  j = 0;
  k = 0;
  while (c != EOF) {
    c = fgetc(fp);
    if (c == '\n') {
      j++;
      i = -1;
    }
    i++;
    if (k < i)
      k = i;
  }
  *w = k;
  *h = j;
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<getProgramSize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeb1(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x30(%rbp),%eax
mov    0x2e71(%rip),%rcx
cmp    (%rcx),%eax
je     11c5 <getProgramSize+0x95>
mov    -0x20(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0xa,-0x30(%rbp)
jne    11a5 <getProgramSize+0x75>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
movl   $0xffffffff,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11c0 <getProgramSize+0x90>
mov    -0x24(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    116d <getProgramSize+0x3d>
mov    -0x2c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getProgramSize>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,0x10(%rsp)
mov    %rsi,0x8(%rsp)
lea    0xeb1(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%r13
xor    %ebp,%ebp
mov    $0xffffffff,%r12d
mov    0x2e82(%rip),%r14
xor    %ebx,%ebx
xor    %r15d,%r15d
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
call   1040 <fgetc@plt>
xor    %ecx,%ecx
cmp    $0xa,%eax
cmove  %r12d,%r15d
sete   %cl
add    %ecx,%ebx
cmp    %r15d,%ebp
lea    0x1(%r15),%ecx
cmovle %ecx,%ebp
mov    %ecx,%r15d
cmp    (%r14),%eax
jne    1170 <getProgramSize+0x40>
mov    0x8(%rsp),%rax
mov    %ebp,(%rax)
mov    0x10(%rsp),%rax
mov    %ebx,(%rax)
mov    %r13,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@EOF = global i32 0
define i32 @getProgramSize(i8* %0, i32* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
%12 = load i8*, i8** %4
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %7
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
br label %14
14: ; preds = %34, %3
%15 = load i32, i32* %11
%16 = load i32, i32* @EOF
%17 = icmp ne i32 %15, %16
br i1 %17, label %18, label %35
18: ; preds = %14
%19 = load i32*, i32** %7
%20 = call i32 @fgetc(i32* %19)
store i32 %20, i32* %11
%21 = load i32, i32* %11
%22 = icmp eq i32 %21, 10
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = load i32, i32* %9
%25 = add nsw i32 %24, 1
store i32 %25, i32* %9
store i32 -1, i32* %8
br label %26
26: ; preds = %23, %18
%27 = load i32, i32* %8
%28 = add nsw i32 %27, 1
store i32 %28, i32* %8
%29 = load i32, i32* %10
%30 = load i32, i32* %8
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %34
32: ; preds = %26
%33 = load i32, i32* %8
store i32 %33, i32* %10
br label %34
34: ; preds = %32, %26
br label %14
35: ; preds = %14
%36 = load i32, i32* %10
%37 = load i32*, i32** %5
store i32 %36, i32* %37
%38 = load i32, i32* %9
%39 = load i32*, i32** %6
store i32 %38, i32* %39
%40 = load i32*, i32** %7
%41 = call i32 @fclose(i32* %40)
ret i32 0
}

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