#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(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, int *, int *);
int /*<<< orphan*/ stderr;
void pgmsize(char *filename, int *nx, int *ny) {
  FILE *fp;
  char *cret;
  int iret;
  char dummy[128];
  int n = 128;
  if (NULL == (fp = fopen(filename, "r"))) {
    fprintf(stderr, "pgmsize: cannot open <%s>\n", filename);
    exit(-1);
  }
  cret = fgets(dummy, n, fp);
  cret = fgets(dummy, n, fp);
  iret = fscanf(fp, "%d %d", nx, ny);
  fclose(fp);
}


x86 assembly (clang, -O0):
<pgmsize>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x80,-0xb4(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe74(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rcx
mov    %rcx,-0x20(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    11c6 <pgmsize+0x66>
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe4b(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
lea    -0xb0(%rbp),%rdi
mov    -0xb4(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1050 <fgets@plt>
mov    %rax,-0x28(%rbp)
lea    -0xb0(%rbp),%rdi
mov    -0xb4(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1050 <fgets@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe10(%rip),%rsi
call   1040 <fscanf@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pgmsize>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
lea    0xe82(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11da <pgmsize+0x7a>
mov    %rax,%rbx
mov    %rsp,%r12
mov    %r12,%rdi
mov    $0x80,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
mov    %r12,%rdi
mov    $0x80,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
lea    0xe68(%rip),%rsi
mov    %rbx,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
call   1040 <fscanf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
lea    0xe18(%rip),%rsi
mov    %r12,%rdx
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"pgmsize: cannot open <%s>\0A\00"
@.str.2 = [6 x i8] c"%d %d\00"
define void @pgmsize(i8* %0, i32* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca [128 x i8]
%11 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
store i32 128, i32* %11
%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
%14 = icmp eq i32* null, %13
br i1 %14, label %15, label %20
15: ; preds = %3
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %4
%18 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = call i32 @exit(i32 -1)
unreachable
20: ; preds = %3
%21 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%22 = load i32, i32* %11
%23 = load i32*, i32** %7
%24 = call i8* @fgets(i8* %21, i32 %22, i32* %23)
store i8* %24, i8** %8
%25 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%26 = load i32, i32* %11
%27 = load i32*, i32** %7
%28 = call i8* @fgets(i8* %25, i32 %26, i32* %27)
store i8* %28, i8** %8
%29 = load i32*, i32** %7
%30 = load i32*, i32** %5
%31 = load i32*, i32** %6
%32 = call i32 @fscanf(i32* %29, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %30, i32* %31)
store i32 %32, i32* %9
%33 = load i32*, i32** %7
%34 = call i32 @fclose(i32* %33)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"pgmsize: cannot open <%s>\0A\00"
@.str.2 = [6 x i8] c"%d %d\00"
define void @pgmsize(i8* %0, i32* %1, i32* %2) {
%4 = alloca [128 x i8]
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %12
8: ; preds = %3
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%11 = tail call i32 @exit(i32 -1)
unreachable
12: ; preds = %3
%13 = call i8* @fgets(i8* %5, i32 128, i32* %6)
%14 = call i8* @fgets(i8* %5, i32 128, i32* %6)
%15 = call i32 @fscanf(i32* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %1, i32* %2)
%16 = call i32 @fclose(i32* %6)
ret void
}