#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*/ scanf(char *, ...);
scalar_t__ strcmp(char *, char *);
int ler_pgm(int img[][400], int *W, int *H, int *MaxV, int *F, double *C,
            double *Gama) {
  char nome_formato[3];
  int i, j;
  scanf("%s ", nome_formato);
  if (strcmp(nome_formato, "P2") != 0)
    return 0;
  scanf("# %d", F);
  if (*F == 1) {
    scanf("%lf %lf", C, Gama);
  }
  scanf("%d", W);
  scanf("%d", H);
  scanf("%d", MaxV);
  for (i = 0; i < (*H); i++) {
    for (j = 0; j < (*W); j++) {
      scanf("%d", &img[i][j]);
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<ler_pgm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
lea    -0x3b(%rbp),%rsi
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1040 <scanf@plt>
lea    -0x3b(%rbp),%rdi
lea    0xea3(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
je     117c <ler_pgm+0x5c>
movl   $0x0,-0x4(%rbp)
jmp    1266 <ler_pgm+0x146>
mov    -0x30(%rbp),%rsi
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x30(%rbp),%rax
cmpl   $0x1,(%rax)
jne    11b1 <ler_pgm+0x91>
mov    -0x38(%rbp),%rsi
mov    0x10(%rbp),%rdx
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x18(%rbp),%rsi
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x20(%rbp),%rsi
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x28(%rbp),%rsi
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1040 <scanf@plt>
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
mov    -0x20(%rbp),%rcx
cmp    (%rcx),%eax
jge    125f <ler_pgm+0x13f>
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jge    124c <ler_pgm+0x12c>
mov    -0x10(%rbp),%rsi
movslq -0x40(%rbp),%rax
imul   $0x640,%rax,%rax
add    %rax,%rsi
movslq -0x44(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xdd2(%rip),%rdi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1204 <ler_pgm+0xe4>
jmp    1251 <ler_pgm+0x131>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    11ee <ler_pgm+0xce>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ler_pgm>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9,0x18(%rsp)
mov    %r8,%r12
mov    %rcx,0x10(%rsp)
mov    %rdx,%rbp
mov    %rsi,%rbx
mov    %rdi,%r15
lea    0xeb5(%rip),%rdi
xor    %r13d,%r13d
lea    0xd(%rsp),%r14
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
lea    0xea0(%rip),%rsi
mov    %r14,%rdi
call   1030 <strcmp@plt>
test   %rax,%rax
jne    124d <ler_pgm+0x12d>
mov    0x18(%rsp),%r14
mov    0x10(%rsp),%r13
lea    0xe81(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
cmpl   $0x1,(%r12)
jne    11ad <ler_pgm+0x8d>
mov    0x60(%rsp),%rdx
lea    0xe69(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
lea    0xe55(%rip),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    %r14,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0x0(%rbp),%ecx
mov    $0x1,%r13d
test   %ecx,%ecx
jle    124d <ler_pgm+0x12d>
mov    (%rbx),%eax
lea    0xe18(%rip),%r12
xor    %r13d,%r13d
mov    %rbp,0x20(%rsp)
jmp    1213 <ler_pgm+0xf3>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r13
movslq %ecx,%rdx
add    $0x640,%r15
cmp    %rdx,%r13
jge    1247 <ler_pgm+0x127>
test   %eax,%eax
jle    1200 <ler_pgm+0xe0>
mov    %r15,%rbp
xor    %r14d,%r14d
nopl   (%rax)
mov    %r12,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
add    $0x1,%r14
movslq (%rbx),%rax
add    $0x4,%rbp
cmp    %rax,%r14
jl     1220 <ler_pgm+0x100>
mov    0x20(%rsp),%rbp
mov    0x0(%rbp),%ecx
jmp    1200 <ler_pgm+0xe0>
mov    $0x1,%r13d
mov    %r13d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%s \00"
@.str.1 = [3 x i8] c"P2\00"
@.str.2 = [5 x i8] c"# %d\00"
@.str.3 = [8 x i8] c"%lf %lf\00"
@.str.4 = [3 x i8] c"%d\00"
define i32 @ler_pgm([400 x i32]* %0, i32* %1, i32* %2, i32* %3, i32* %4, double* %5, double* %6) {
%8 = alloca i32
%9 = alloca [400 x i32]*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca double*
%15 = alloca double*
%16 = alloca [3 x i8]
%17 = alloca i32
%18 = alloca i32
store [400 x i32]* %0, [400 x i32]** %9
store i32* %1, i32** %10
store i32* %2, i32** %11
store i32* %3, i32** %12
store i32* %4, i32** %13
store double* %5, double** %14
store double* %6, double** %15
%19 = getelementptr inbounds [3 x i8], [3 x i8]* %16, i64 0, i64 0
%20 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = getelementptr inbounds [3 x i8], [3 x i8]* %16, i64 0, i64 0
%22 = call i64 @strcmp(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %7
store i32 0, i32* %8
br label %70
25: ; preds = %7
%26 = load i32*, i32** %13
%27 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32* %26)
%28 = load i32*, i32** %13
%29 = load i32, i32* %28
%30 = icmp eq i32 %29, 1
br i1 %30, label %31, label %35
31: ; preds = %25
%32 = load double*, double** %14
%33 = load double*, double** %15
%34 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), double* %32, double* %33)
br label %35
35: ; preds = %31, %25
%36 = load i32*, i32** %10
%37 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %36)
%38 = load i32*, i32** %11
%39 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %38)
%40 = load i32*, i32** %12
%41 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %40)
store i32 0, i32* %17
br label %42
42: ; preds = %66, %35
%43 = load i32, i32* %17
%44 = load i32*, i32** %11
%45 = load i32, i32* %44
%46 = icmp slt i32 %43, %45
br i1 %46, label %47, label %69
47: ; preds = %42
store i32 0, i32* %18
br label %48
48: ; preds = %62, %47
%49 = load i32, i32* %18
%50 = load i32*, i32** %10
%51 = load i32, i32* %50
%52 = icmp slt i32 %49, %51
br i1 %52, label %53, label %65
53: ; preds = %48
%54 = load [400 x i32]*, [400 x i32]** %9
%55 = load i32, i32* %17
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [400 x i32], [400 x i32]* %54, i64 %56
%58 = load i32, i32* %18
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds [400 x i32], [400 x i32]* %57, i64 0, i64 %59
%61 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %60)
br label %62
62: ; preds = %53
%63 = load i32, i32* %18
%64 = add nsw i32 %63, 1
store i32 %64, i32* %18
br label %48
65: ; preds = %48
br label %66
66: ; preds = %65
%67 = load i32, i32* %17
%68 = add nsw i32 %67, 1
store i32 %68, i32* %17
br label %42
69: ; preds = %42
store i32 1, i32* %8
br label %70
70: ; preds = %69, %24
%71 = load i32, i32* %8
ret i32 %71
}

LLVM IR (-O2):
@.str = [4 x i8] c"%s \00"
@.str.1 = [3 x i8] c"P2\00"
@.str.2 = [5 x i8] c"# %d\00"
@.str.3 = [8 x i8] c"%lf %lf\00"
@.str.4 = [3 x i8] c"%d\00"
define i32 @ler_pgm([400 x i32]* %0, i32* %1, i32* %2, i32* %3, i32* %4, double* %5, double* %6) {
%8 = alloca [3 x i8]
%9 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 0
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %48
13: ; preds = %7
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%15 = load i32, i32* %4
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), double* %5, double* %6)
br label %19
19: ; preds = %17, %13
%20 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %1)
%21 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %2)
%22 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %3)
%23 = load i32, i32* %2
%24 = icmp sgt i32 %23, 0
br i1 %24, label %25, label %48
25: ; preds = %19
%26 = load i32, i32* %1
br label %27
27: ; preds = %25, %42
%28 = phi i32 [ %23, %25 ], [ %43, %42 ]
%29 = phi i32 [ %26, %25 ], [ %44, %42 ]
%30 = phi i64 [ 0, %25 ], [ %45, %42 ]
%31 = icmp sgt i32 %29, 0
br i1 %31, label %32, label %42
32: ; preds = %27, %32
%33 = phi i64 [ %36, %32 ], [ 0, %27 ]
%34 = getelementptr inbounds [400 x i32], [400 x i32]* %0, i64 %30, i64 %33
%35 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %34)
%36 = add nuw nsw i64 %33, 1
%37 = load i32, i32* %1
%38 = sext i32 %37 to i64
%39 = icmp slt i64 %36, %38
br i1 %39, label %32, label %40
40: ; preds = %32
%41 = load i32, i32* %2
br label %42
42: ; preds = %40, %27
%43 = phi i32 [ %41, %40 ], [ %28, %27 ]
%44 = phi i32 [ %37, %40 ], [ %29, %27 ]
%45 = add nuw nsw i64 %30, 1
%46 = sext i32 %43 to i64
%47 = icmp slt i64 %45, %46
br i1 %47, label %27, label %48
48: ; preds = %42, %19, %7
%49 = phi i32 [ 0, %7 ], [ 1, %19 ], [ 1, %42 ]
ret i32 %49
}