#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 */

/* Variables and functions */
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ gaussian5x5int(unsigned char *, unsigned char *, int, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ readPGM(unsigned char **, char *, int *, int *, int *);
int /*<<< orphan*/ writePGM(unsigned char *, char *, int, int, int);
int main(int argc, char *argv[]) {
  if (argc != 3) {
    printf("Usage: gaussian5x5int input.pgm output.pgm\n");
    return -1;
  }
  unsigned char *image_in;
  unsigned char *image_out;
  int w;
  int h;
  int grayMax;
  readPGM(&image_in, argv[1], &w, &h, &grayMax);
  printf("Image File Name: %s\n", argv[1]);
  printf("Image Width: %d\n", w);
  printf("Image Height: %d\n", h);
  image_out = (unsigned char *)malloc(w * h * sizeof(unsigned char));
  gaussian5x5int((unsigned char *)image_out, (unsigned char *)image_in, w, h);
  writePGM(image_out, argv[2], w, h, grayMax);
  free(image_in);
  free(image_out);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     119a <main+0x3a>
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    124e <main+0xee>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    -0x18(%rbp),%rdi
lea    -0x24(%rbp),%rdx
lea    -0x28(%rbp),%rcx
lea    -0x2c(%rbp),%r8
call   1050 <readPGM@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x24(%rbp),%esi
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x28(%rbp),%esi
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x24(%rbp),%eax
imul   -0x28(%rbp),%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    -0x28(%rbp),%ecx
call   1040 <gaussian5x5int@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
mov    -0x24(%rbp),%edx
mov    -0x28(%rbp),%ecx
mov    -0x2c(%rbp),%r8d
call   1070 <writePGM@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
cmp    $0x3,%edi
jne    122d <main+0xbd>
mov    %rsi,%rbx
mov    0x8(%rsi),%rsi
lea    0x18(%rsp),%rdi
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
lea    0x14(%rsp),%r8
call   1060 <readPGM@plt>
mov    0x8(%rbx),%rsi
lea    0xe54(%rip),%rdi
xor    %r14d,%r14d
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x10(%rsp),%esi
lea    0xe54(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0xc(%rsp),%esi
lea    0xe53(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0xc(%rsp),%edi
imul   0x10(%rsp),%edi
call   1090 <malloc@plt>
mov    %rax,%rbp
mov    0x18(%rsp),%rsi
mov    0x10(%rsp),%edx
mov    0xc(%rsp),%ecx
mov    %rax,%rdi
call   1040 <gaussian5x5int@plt>
mov    0x10(%rbx),%rsi
mov    0x10(%rsp),%edx
mov    0xc(%rsp),%ecx
mov    0x14(%rsp),%r8d
mov    %rbp,%rdi
call   1080 <writePGM@plt>
mov    0x18(%rsp),%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
jmp    123f <main+0xcf>
lea    0xe04(%rip),%rdi
call   1050 <puts@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [44 x i8] c"Usage: gaussian5x5int input.pgm output.pgm\0A\00"
@.str.1 = [21 x i8] c"Image File Name: %s\0A\00"
@.str.2 = [17 x i8] c"Image Width: %d\0A\00"
@.str.3 = [18 x i8] c"Image Height: %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 3
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %53
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @readPGM(i8** %6, i8* %18, i32* %8, i32* %9, i32* %10)
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %22)
%24 = load i32, i32* %8
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %24)
%26 = load i32, i32* %9
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %26)
%28 = load i32, i32* %8
%29 = load i32, i32* %9
%30 = mul nsw i32 %28, %29
%31 = sext i32 %30 to i64
%32 = mul i64 %31, 1
%33 = trunc i64 %32 to i32
%34 = call i64 @malloc(i32 %33)
%35 = inttoptr i64 %34 to i8*
store i8* %35, i8** %7
%36 = load i8*, i8** %7
%37 = load i8*, i8** %6
%38 = load i32, i32* %8
%39 = load i32, i32* %9
%40 = call i32 @gaussian5x5int(i8* %36, i8* %37, i32 %38, i32 %39)
%41 = load i8*, i8** %7
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 2
%44 = load i8*, i8** %43
%45 = load i32, i32* %8
%46 = load i32, i32* %9
%47 = load i32, i32* %10
%48 = call i32 @writePGM(i8* %41, i8* %44, i32 %45, i32 %46, i32 %47)
%49 = load i8*, i8** %6
%50 = call i32 @free(i8* %49)
%51 = load i8*, i8** %7
%52 = call i32 @free(i8* %51)
store i32 0, i32* %3
br label %53
53: ; preds = %15, %13
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
@.str.1 = [21 x i8] c"Image File Name: %s\0A\00"
@.str.2 = [17 x i8] c"Image Width: %d\0A\00"
@.str.3 = [18 x i8] c"Image Height: %d\0A\00"
@str = [43 x i8] c"Usage: gaussian5x5int input.pgm output.pgm\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = icmp eq i32 %0, 3
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str, i64 0, i64 0))
br label %42
10: ; preds = %2
%11 = bitcast i8** %3 to i8*
%12 = bitcast i32* %4 to i8*
%13 = bitcast i32* %5 to i8*
%14 = bitcast i32* %6 to i8*
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @readPGM(i8** %3, i8* %16, i32* %4, i32* %5, i32* %6)
%18 = load i8*, i8** %15
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = load i32, i32* %4
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %20)
%22 = load i32, i32* %5
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %22)
%24 = load i32, i32* %4
%25 = load i32, i32* %5
%26 = mul nsw i32 %25, %24
%27 = call i64 @malloc(i32 %26)
%28 = inttoptr i64 %27 to i8*
%29 = load i8*, i8** %3
%30 = load i32, i32* %4
%31 = load i32, i32* %5
%32 = call i32 @gaussian5x5int(i8* %28, i8* %29, i32 %30, i32 %31)
%33 = getelementptr inbounds i8*, i8** %1, i64 2
%34 = load i8*, i8** %33
%35 = load i32, i32* %4
%36 = load i32, i32* %5
%37 = load i32, i32* %6
%38 = call i32 @writePGM(i8* %28, i8* %34, i32 %35, i32 %36, i32 %37)
%39 = load i8*, i8** %3
%40 = call i32 @free(i8* %39)
%41 = call i32 @free(i8* %28)
br label %42
42: ; preds = %10, %8
%43 = phi i32 [ -1, %8 ], [ 0, %10 ]
ret i32 %43
}