#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*/ escrever_pgm(int **, int, int, int);
int /*<<< orphan*/ espelhamento(int **, int, int);
int ler_pgm(int **, int *, int *, int *, int *, double *, double *);
int /*<<< orphan*/ potencia(int **, int, int, int, double, double);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ reducaoRuido(int **, int, int, int);
int /*<<< orphan*/ rotacao(int **, int, int);
int main() {
  int img[400][400];
  int W, H, MaxV, aux;
  int F;
  double C, Gama;
  if (ler_pgm(img, &W, &H, &MaxV, &F, &C, &Gama) != 1) {
    printf("Error: nao foi possivel ler a imagem\n");
    return 0;
  }
  switch (F) {
  case 1:
    potencia(img, W, H, MaxV, C, Gama);
    break;
  case 2:
    espelhamento(img, W, H);
    break;
  case 3:
    reducaoRuido(img, W, H, MaxV);
    break;
  case 4:
    rotacao(img, W, H);
    aux = W;
    W = H;
    H = aux;
    break;
  }
  escrever_pgm(img, W, H, MaxV);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x9c450,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x9c410(%rbp),%rdi
lea    -0x9c414(%rbp),%rsi
lea    -0x9c418(%rbp),%rdx
lea    -0x9c41c(%rbp),%rcx
lea    -0x9c424(%rbp),%r8
lea    -0x9c430(%rbp),%r9
lea    -0x9c438(%rbp),%rax
mov    %rax,(%rsp)
call   1080 <ler_pgm@plt>
cmp    $0x1,%eax
je     11dd <main+0x6d>
lea    0xe44(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12e3 <main+0x173>
mov    -0x9c424(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x9c440(%rbp)
sub    $0x3,%eax
ja     12be <main+0x14e>
mov    -0x9c440(%rbp),%rax
lea    0xdfa(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    -0x9c410(%rbp),%rdi
mov    -0x9c414(%rbp),%esi
mov    -0x9c418(%rbp),%edx
mov    -0x9c41c(%rbp),%ecx
movsd  -0x9c430(%rbp),%xmm0
ff
movsd  -0x9c438(%rbp),%xmm1
ff
call   1090 <potencia@plt>
jmp    12be <main+0x14e>
lea    -0x9c410(%rbp),%rdi
mov    -0x9c414(%rbp),%esi
mov    -0x9c418(%rbp),%edx
call   1060 <espelhamento@plt>
jmp    12be <main+0x14e>
lea    -0x9c410(%rbp),%rdi
mov    -0x9c414(%rbp),%esi
mov    -0x9c418(%rbp),%edx
mov    -0x9c41c(%rbp),%ecx
call   1070 <reducaoRuido@plt>
jmp    12be <main+0x14e>
lea    -0x9c410(%rbp),%rdi
mov    -0x9c414(%rbp),%esi
mov    -0x9c418(%rbp),%edx
call   1040 <rotacao@plt>
mov    -0x9c414(%rbp),%eax
mov    %eax,-0x9c420(%rbp)
mov    -0x9c418(%rbp),%eax
mov    %eax,-0x9c414(%rbp)
mov    -0x9c420(%rbp),%eax
mov    %eax,-0x9c418(%rbp)
lea    -0x9c410(%rbp),%rdi
mov    -0x9c414(%rbp),%esi
mov    -0x9c418(%rbp),%edx
mov    -0x9c41c(%rbp),%ecx
call   1030 <escrever_pgm@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x9c450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x9c438,%rsp
lea    0x20(%rsp),%rax
mov    %rax,(%rsp)
lea    0x30(%rsp),%rdi
lea    0x14(%rsp),%rsi
lea    0x10(%rsp),%rdx
lea    0x18(%rsp),%rcx
lea    0x1c(%rsp),%r8
lea    0x28(%rsp),%r9
call   1080 <ler_pgm@plt>
cmp    $0x1,%eax
jne    11ec <main+0x7c>
mov    0x1c(%rsp),%eax
add    $0xffffffff,%eax
cmp    $0x3,%eax
ja     1248 <main+0xd8>
lea    0xe41(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x14(%rsp),%esi
mov    0x10(%rsp),%edx
mov    0x18(%rsp),%ecx
movsd  0x28(%rsp),%xmm0
movsd  0x20(%rsp),%xmm1
lea    0x30(%rsp),%rdi
call   1090 <potencia@plt>
jmp    1248 <main+0xd8>
lea    0xe1d(%rip),%rdi
call   1030 <puts@plt>
jmp    125e <main+0xee>
mov    0x14(%rsp),%esi
mov    0x10(%rsp),%edx
lea    0x30(%rsp),%rdi
call   1060 <espelhamento@plt>
jmp    1248 <main+0xd8>
mov    0x14(%rsp),%esi
mov    0x10(%rsp),%edx
mov    0x18(%rsp),%ecx
lea    0x30(%rsp),%rdi
call   1070 <reducaoRuido@plt>
jmp    1248 <main+0xd8>
mov    0x14(%rsp),%esi
mov    0x10(%rsp),%edx
lea    0x30(%rsp),%rdi
call   1050 <rotacao@plt>
mov    0x14(%rsp),%eax
mov    0x10(%rsp),%ecx
mov    %ecx,0x14(%rsp)
mov    %eax,0x10(%rsp)
mov    0x14(%rsp),%esi
mov    0x10(%rsp),%edx
mov    0x18(%rsp),%ecx
lea    0x30(%rsp),%rdi
call   1040 <escrever_pgm@plt>
xor    %eax,%eax
add    $0x9c438,%rsp
ret

LLVM IR (-O0):
@.str = [38 x i8] c"Error: nao foi possivel ler a imagem\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [400 x [400 x i32]]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca double
%9 = alloca double
store i32 0, i32* %1
%10 = getelementptr inbounds [400 x [400 x i32]], [400 x [400 x i32]]* %2, i64 0, i64 0
%11 = bitcast [400 x i32]* %10 to i32**
%12 = call i32 @ler_pgm(i32** %11, i32* %3, i32* %4, i32* %5, i32* %7, double* %8, double* %9)
%13 = icmp ne i32 %12, 1
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
br label %56
16: ; preds = %0
%17 = load i32, i32* %7
switch i32 %17, label %49 [
i32 1, label %18
i32 2, label %27
i32 3, label %33
i32 4, label %40
]
18: ; preds = %16
%19 = getelementptr inbounds [400 x [400 x i32]], [400 x [400 x i32]]* %2, i64 0, i64 0
%20 = bitcast [400 x i32]* %19 to i32**
%21 = load i32, i32* %3
%22 = load i32, i32* %4
%23 = load i32, i32* %5
%24 = load double, double* %8
%25 = load double, double* %9
%26 = call i32 @potencia(i32** %20, i32 %21, i32 %22, i32 %23, double %24, double %25)
br label %49
27: ; preds = %16
%28 = getelementptr inbounds [400 x [400 x i32]], [400 x [400 x i32]]* %2, i64 0, i64 0
%29 = bitcast [400 x i32]* %28 to i32**
%30 = load i32, i32* %3
%31 = load i32, i32* %4
%32 = call i32 @espelhamento(i32** %29, i32 %30, i32 %31)
br label %49
33: ; preds = %16
%34 = getelementptr inbounds [400 x [400 x i32]], [400 x [400 x i32]]* %2, i64 0, i64 0
%35 = bitcast [400 x i32]* %34 to i32**
%36 = load i32, i32* %3
%37 = load i32, i32* %4
%38 = load i32, i32* %5
%39 = call i32 @reducaoRuido(i32** %35, i32 %36, i32 %37, i32 %38)
br label %49
40: ; preds = %16
%41 = getelementptr inbounds [400 x [400 x i32]], [400 x [400 x i32]]* %2, i64 0, i64 0
%42 = bitcast [400 x i32]* %41 to i32**
%43 = load i32, i32* %3
%44 = load i32, i32* %4
%45 = call i32 @rotacao(i32** %42, i32 %43, i32 %44)
%46 = load i32, i32* %3
store i32 %46, i32* %6
%47 = load i32, i32* %4
store i32 %47, i32* %3
%48 = load i32, i32* %6
store i32 %48, i32* %4
br label %49
49: ; preds = %16, %40, %33, %27, %18
%50 = getelementptr inbounds [400 x [400 x i32]], [400 x [400 x i32]]* %2, i64 0, i64 0
%51 = bitcast [400 x i32]* %50 to i32**
%52 = load i32, i32* %3
%53 = load i32, i32* %4
%54 = load i32, i32* %5
%55 = call i32 @escrever_pgm(i32** %51, i32 %52, i32 %53, i32 %54)
store i32 0, i32* %1
br label %56
56: ; preds = %49, %14
%57 = load i32, i32* %1
ret i32 %57
}

LLVM IR (-O2):
@str = [37 x i8] c"Error: nao foi possivel ler a imagem\00"
define i32 @main() {
%1 = alloca [400 x [400 x i32]]
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca double
%7 = alloca double
%8 = bitcast [400 x [400 x i32]]* %1 to i8*
%9 = bitcast i32* %2 to i8*
%10 = bitcast i32* %3 to i8*
%11 = bitcast i32* %4 to i8*
%12 = bitcast i32* %5 to i8*
%13 = bitcast double* %6 to i8*
%14 = bitcast double* %7 to i8*
%15 = bitcast [400 x [400 x i32]]* %1 to i32**
%16 = call i32 @ler_pgm(i32** %15, i32* %2, i32* %3, i32* %4, i32* %5, double* %6, double* %7)
%17 = icmp eq i32 %16, 1
br i1 %17, label %20, label %18
18: ; preds = %0
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
br label %49
20: ; preds = %0
%21 = load i32, i32* %5
switch i32 %21, label %44 [
i32 1, label %22
i32 2, label %29
i32 3, label %33
i32 4, label %38
]
22: ; preds = %20
%23 = load i32, i32* %2
%24 = load i32, i32* %3
%25 = load i32, i32* %4
%26 = load double, double* %6
%27 = load double, double* %7
%28 = call i32 @potencia(i32** %15, i32 %23, i32 %24, i32 %25, double %26, double %27)
br label %44
29: ; preds = %20
%30 = load i32, i32* %2
%31 = load i32, i32* %3
%32 = call i32 @espelhamento(i32** %15, i32 %30, i32 %31)
br label %44
33: ; preds = %20
%34 = load i32, i32* %2
%35 = load i32, i32* %3
%36 = load i32, i32* %4
%37 = call i32 @reducaoRuido(i32** %15, i32 %34, i32 %35, i32 %36)
br label %44
38: ; preds = %20
%39 = load i32, i32* %2
%40 = load i32, i32* %3
%41 = call i32 @rotacao(i32** %15, i32 %39, i32 %40)
%42 = load i32, i32* %2
%43 = load i32, i32* %3
store i32 %43, i32* %2
store i32 %42, i32* %3
br label %44
44: ; preds = %20, %38, %33, %29, %22
%45 = load i32, i32* %2
%46 = load i32, i32* %3
%47 = load i32, i32* %4
%48 = call i32 @escrever_pgm(i32** %15, i32 %45, i32 %46, i32 %47)
br label %49
49: ; preds = %44, %18
ret i32 0
}