#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 **Matrix_Alloc(int **, int, int);
int /*<<< orphan*/ Matrix_Free(int **, int);
int bmp256(char *, int **, int *);
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ printf(char *);
int salvar(char *, char *, int **, int *);
int /*<<< orphan*/ scanf(char *, ...);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
int main() {
  int fc[3], s, c, op, c1, l1, tm;
  float fil[13][13];
  int brillo, contraste, i, j;
  char nombre1[12], nombre2[12], nombrea[12];
  int m = 1000, n = 1000;
  int **mat = NULL;
  mat = Matrix_Alloc(mat, m, n);
  printf("ingrese archivo:");
  scanf("%s", nombre1);
  strcat(nombre1, ".bmp");
  c = bmp256(nombre1, mat, fc);
  if (c == 0) {
    printf("no se pudo abrir el archivo!! \n");
    getchar();
    return 0;
  }
  printf("ingrese archivo destino: ");
  scanf("%s", nombre2);
  printf("ingrese el umbral: ");
  int umbral;
  scanf("%d", &umbral);
  for (i = 0; i < fc[0]; i++) {
    for (j = 0; j < fc[1]; j++) {
      if (mat[i][j] > umbral)
        mat[i][j] = 255;
      else
        mat[i][j] = 0;
    }
  }
  l1 = strlen(nombre2);
  for (i = 0; i < l1; i++)
    nombrea[i] = nombre2[i];
  strcat(nombre2, ".bmp");
  s = salvar(nombre1, nombre2, mat, fc);
  printf("Finalizado, press. ENTER.....");
  getchar();
  Matrix_Free(mat, m);
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x320,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x3e8,-0x308(%rbp)
movl   $0x3e8,-0x30c(%rbp)
movq   $0x0,-0x318(%rbp)
mov    -0x318(%rbp),%rdi
mov    -0x308(%rbp),%esi
mov    -0x30c(%rbp),%edx
call   1090 <Matrix_Alloc@plt>
mov    %rax,-0x318(%rbp)
lea    0xe19(%rip),%rdi
call   1060 <printf@plt>
lea    -0x2ec(%rbp),%rsi
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   10a0 <scanf@plt>
lea    -0x2ec(%rbp),%rdi
lea    0xe05(%rip),%rsi
call   10b0 <strcat@plt>
lea    -0x2ec(%rbp),%rdi
mov    -0x318(%rbp),%rsi
lea    -0x10(%rbp),%rdx
call   1040 <bmp256@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    1257 <main+0xc7>
lea    0xdda(%rip),%rdi
call   1060 <printf@plt>
mov    $0x0,%al
call   1070 <getchar@plt>
movl   $0x0,-0x4(%rbp)
jmp    1422 <main+0x292>
lea    0xddb(%rip),%rdi
call   1060 <printf@plt>
lea    -0x2f8(%rbp),%rsi
lea    0xda0(%rip),%rdi
mov    $0x0,%al
call   10a0 <scanf@plt>
lea    0xdd4(%rip),%rdi
call   1060 <printf@plt>
lea    0xddc(%rip),%rdi
lea    -0x31c(%rbp),%rsi
mov    $0x0,%al
call   10a0 <scanf@plt>
movl   $0x0,-0x2dc(%rbp)
mov    -0x2dc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    136a <main+0x1da>
movl   $0x0,-0x2e0(%rbp)
mov    -0x2e0(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1351 <main+0x1c1>
mov    -0x318(%rbp),%rax
movslq -0x2dc(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x2e0(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x31c(%rbp),%eax
jle    1318 <main+0x188>
mov    -0x318(%rbp),%rax
movslq -0x2dc(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x2e0(%rbp),%rcx
movl   $0xff,(%rax,%rcx,4)
jmp    1338 <main+0x1a8>
mov    -0x318(%rbp),%rax
movslq -0x2dc(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x2e0(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
jmp    133d <main+0x1ad>
mov    -0x2e0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2e0(%rbp)
jmp    12bc <main+0x12c>
jmp    1356 <main+0x1c6>
mov    -0x2dc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2dc(%rbp)
jmp    12a3 <main+0x113>
lea    -0x2f8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x2dc(%rbp)
mov    -0x2dc(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    13c2 <main+0x232>
movslq -0x2dc(%rbp),%rax
mov    -0x2f8(%rbp,%rax,1),%cl
movslq -0x2dc(%rbp),%rax
mov    %cl,-0x304(%rbp,%rax,1)
mov    -0x2dc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2dc(%rbp)
jmp    1383 <main+0x1f3>
lea    -0x2f8(%rbp),%rdi
lea    0xc44(%rip),%rsi
call   10b0 <strcat@plt>
lea    -0x2ec(%rbp),%rdi
lea    -0x2f8(%rbp),%rsi
mov    -0x318(%rbp),%rdx
lea    -0x10(%rbp),%rcx
call   1030 <salvar@plt>
mov    %eax,-0x14(%rbp)
lea    0xc6d(%rip),%rdi
call   1060 <printf@plt>
mov    $0x0,%al
call   1070 <getchar@plt>
mov    -0x318(%rbp),%rdi
mov    -0x308(%rbp),%esi
call   1080 <Matrix_Free@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x320,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
xor    %r14d,%r14d
xor    %edi,%edi
mov    $0x3e8,%esi
mov    $0x3e8,%edx
call   10a0 <Matrix_Alloc@plt>
mov    %rax,%r12
lea    0xe37(%rip),%rdi
call   1070 <printf@plt>
lea    0xe3c(%rip),%rdi
lea    0x1c(%rsp),%r15
mov    %r15,%rsi
xor    %eax,%eax
call   10b0 <scanf@plt>
lea    0xe29(%rip),%rsi
mov    %r15,%rdi
call   10c0 <strcat@plt>
lea    0x4(%rsp),%rdx
mov    %r15,%rdi
mov    %r12,%rsi
call   1040 <bmp256@plt>
test   %eax,%eax
je     12fe <main+0x15e>
lea    0xe07(%rip),%rdi
call   1070 <printf@plt>
lea    0xdf3(%rip),%rdi
xor    %ebx,%ebx
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   10b0 <scanf@plt>
lea    0xe00(%rip),%rdi
call   1070 <printf@plt>
lea    0xe08(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   10b0 <scanf@plt>
mov    0x4(%rsp),%edx
test   %edx,%edx
jle    12a5 <main+0x105>
mov    0x8(%rsp),%ecx
mov    $0xff,%eax
jmp    126c <main+0xcc>
nopl   0x0(%rax)
add    $0x1,%rbx
movslq %edx,%rsi
cmp    %rsi,%rbx
jge    12a5 <main+0x105>
test   %ecx,%ecx
jle    1260 <main+0xc0>
mov    (%r12,%rbx,8),%rdx
xor    %esi,%esi
cs nopw 0x0(%rax,%rax,1)
mov    (%rdx,%rsi,4),%ecx
cmp    (%rsp),%ecx
mov    $0x0,%ecx
cmovg  %eax,%ecx
mov    %ecx,(%rdx,%rsi,4)
add    $0x1,%rsi
movslq 0x8(%rsp),%rcx
cmp    %rcx,%rsi
jl     1280 <main+0xe0>
mov    0x4(%rsp),%edx
jmp    1260 <main+0xc0>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   1060 <strlen@plt>
lea    0xd5b(%rip),%rsi
mov    %r14,%rdi
call   10c0 <strcat@plt>
lea    0x1c(%rsp),%rdi
lea    0x4(%rsp),%rcx
mov    %r14,%rsi
mov    %r12,%rdx
call   1030 <salvar@plt>
lea    0xd6d(%rip),%rdi
call   1070 <printf@plt>
xor    %eax,%eax
call   1080 <getchar@plt>
mov    %r12,%rdi
mov    $0x3e8,%esi
call   1090 <Matrix_Free@plt>
mov    $0x1,%r14d
jmp    1311 <main+0x171>
lea    0xd63(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
call   1080 <getchar@plt>
mov    %r14d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [17 x i8] c"ingrese archivo:\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [5 x i8] c".bmp\00"
@.str.3 = [32 x i8] c"no se pudo abrir el archivo!! \0A\00"
@.str.4 = [26 x i8] c"ingrese archivo destino: \00"
@.str.5 = [20 x i8] c"ingrese el umbral: \00"
@.str.6 = [3 x i8] c"%d\00"
@.str.7 = [30 x i8] c"Finalizado, press. ENTER.....\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [3 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [13 x [13 x float]]
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca [12 x i8]
%15 = alloca [12 x i8]
%16 = alloca [12 x i8]
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32**
%20 = alloca i32
store i32 0, i32* %1
store i32 1000, i32* %17
store i32 1000, i32* %18
store i32** null, i32*** %19
%21 = load i32**, i32*** %19
%22 = load i32, i32* %17
%23 = load i32, i32* %18
%24 = call i32** @Matrix_Alloc(i32** %21, i32 %22, i32 %23)
store i32** %24, i32*** %19
%25 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%26 = getelementptr inbounds [12 x i8], [12 x i8]* %14, i64 0, i64 0
%27 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %26)
%28 = getelementptr inbounds [12 x i8], [12 x i8]* %14, i64 0, i64 0
%29 = call i32 @strcat(i8* %28, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%30 = getelementptr inbounds [12 x i8], [12 x i8]* %14, i64 0, i64 0
%31 = load i32**, i32*** %19
%32 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 0
%33 = call i32 @bmp256(i8* %30, i32** %31, i32* %32)
store i32 %33, i32* %4
%34 = load i32, i32* %4
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %0
%37 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
%38 = call i32 (...) @getchar()
store i32 0, i32* %1
br label %125
39: ; preds = %0
%40 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%41 = getelementptr inbounds [12 x i8], [12 x i8]* %15, i64 0, i64 0
%42 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %41)
%43 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
%44 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %20)
store i32 0, i32* %12
br label %45
45: ; preds = %91, %39
%46 = load i32, i32* %12
%47 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 0
%48 = load i32, i32* %47
%49 = icmp slt i32 %46, %48
br i1 %49, label %50, label %94
50: ; preds = %45
store i32 0, i32* %13
br label %51
51: ; preds = %87, %50
%52 = load i32, i32* %13
%53 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 1
%54 = load i32, i32* %53
%55 = icmp slt i32 %52, %54
br i1 %55, label %56, label %90
56: ; preds = %51
%57 = load i32**, i32*** %19
%58 = load i32, i32* %12
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i32*, i32** %57, i64 %59
%61 = load i32*, i32** %60
%62 = load i32, i32* %13
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i32, i32* %61, i64 %63
%65 = load i32, i32* %64
%66 = load i32, i32* %20
%67 = icmp sgt i32 %65, %66
br i1 %67, label %68, label %77
68: ; preds = %56
%69 = load i32**, i32*** %19
%70 = load i32, i32* %12
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i32*, i32** %69, i64 %71
%73 = load i32*, i32** %72
%74 = load i32, i32* %13
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds i32, i32* %73, i64 %75
store i32 255, i32* %76
br label %86
77: ; preds = %56
%78 = load i32**, i32*** %19
%79 = load i32, i32* %12
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds i32*, i32** %78, i64 %80
%82 = load i32*, i32** %81
%83 = load i32, i32* %13
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds i32, i32* %82, i64 %84
store i32 0, i32* %85
br label %86
86: ; preds = %77, %68
br label %87
87: ; preds = %86
%88 = load i32, i32* %13
%89 = add nsw i32 %88, 1
store i32 %89, i32* %13
br label %51
90: ; preds = %51
br label %91
91: ; preds = %90
%92 = load i32, i32* %12
%93 = add nsw i32 %92, 1
store i32 %93, i32* %12
br label %45
94: ; preds = %45
%95 = getelementptr inbounds [12 x i8], [12 x i8]* %15, i64 0, i64 0
%96 = call i32 @strlen(i8* %95)
store i32 %96, i32* %7
store i32 0, i32* %12
br label %97
97: ; preds = %109, %94
%98 = load i32, i32* %12
%99 = load i32, i32* %7
%100 = icmp slt i32 %98, %99
br i1 %100, label %101, label %112
101: ; preds = %97
%102 = load i32, i32* %12
%103 = sext i32 %102 to i64
%104 = getelementptr inbounds [12 x i8], [12 x i8]* %15, i64 0, i64 %103
%105 = load i8, i8* %104
%106 = load i32, i32* %12
%107 = sext i32 %106 to i64
%108 = getelementptr inbounds [12 x i8], [12 x i8]* %16, i64 0, i64 %107
store i8 %105, i8* %108
br label %109
109: ; preds = %101
%110 = load i32, i32* %12
%111 = add nsw i32 %110, 1
store i32 %111, i32* %12
br label %97
112: ; preds = %97
%113 = getelementptr inbounds [12 x i8], [12 x i8]* %15, i64 0, i64 0
%114 = call i32 @strcat(i8* %113, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%115 = getelementptr inbounds [12 x i8], [12 x i8]* %14, i64 0, i64 0
%116 = getelementptr inbounds [12 x i8], [12 x i8]* %15, i64 0, i64 0
%117 = load i32**, i32*** %19
%118 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 0
%119 = call i32 @salvar(i8* %115, i8* %116, i32** %117, i32* %118)
store i32 %119, i32* %3
%120 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0))
%121 = call i32 (...) @getchar()
%122 = load i32**, i32*** %19
%123 = load i32, i32* %17
%124 = call i32 @Matrix_Free(i32** %122, i32 %123)
store i32 1, i32* %1
br label %125
125: ; preds = %112, %36
%126 = load i32, i32* %1
ret i32 %126
}

LLVM IR (-O2):
@.str = [17 x i8] c"ingrese archivo:\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [5 x i8] c".bmp\00"
@.str.4 = [26 x i8] c"ingrese archivo destino: \00"
@.str.5 = [20 x i8] c"ingrese el umbral: \00"
@.str.6 = [3 x i8] c"%d\00"
@.str.7 = [30 x i8] c"Finalizado, press. ENTER.....\00"
@str = [31 x i8] c"no se pudo abrir el archivo!! \00"
define i32 @main() {
%1 = alloca [3 x i32]
%2 = alloca [12 x i8]
%3 = alloca [12 x i8]
%4 = alloca i32
%5 = bitcast [3 x i32]* %1 to i8*
%6 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%8 = tail call i32** @Matrix_Alloc(i32** null, i32 1000, i32 1000)
%9 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%11 = call i32 @strcat(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%12 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 0
%13 = call i32 @bmp256(i8* %6, i32** %8, i32* %12)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %0
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%17 = call i32 (...) @getchar()
br label %63
18: ; preds = %0
%19 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%20 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%21 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
%22 = bitcast i32* %4 to i8*
%23 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %4)
%24 = load i32, i32* %12
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %56
26: ; preds = %18
%27 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 1
%28 = load i32, i32* %27
br label %29
29: ; preds = %26, %50
%30 = phi i32 [ %24, %26 ], [ %51, %50 ]
%31 = phi i32 [ %28, %26 ], [ %52, %50 ]
%32 = phi i64 [ 0, %26 ], [ %53, %50 ]
%33 = icmp sgt i32 %31, 0
br i1 %33, label %34, label %50
34: ; preds = %29
%35 = getelementptr inbounds i32*, i32** %8, i64 %32
%36 = load i32*, i32** %35
br label %37
37: ; preds = %34, %37
%38 = phi i64 [ 0, %34 ], [ %44, %37 ]
%39 = getelementptr inbounds i32, i32* %36, i64 %38
%40 = load i32, i32* %39
%41 = load i32, i32* %4
%42 = icmp sgt i32 %40, %41
%43 = select i1 %42, i32 255, i32 0
store i32 %43, i32* %39
%44 = add nuw nsw i64 %38, 1
%45 = load i32, i32* %27
%46 = sext i32 %45 to i64
%47 = icmp slt i64 %44, %46
br i1 %47, label %37, label %48
48: ; preds = %37
%49 = load i32, i32* %12
br label %50
50: ; preds = %48, %29
%51 = phi i32 [ %49, %48 ], [ %30, %29 ]
%52 = phi i32 [ %45, %48 ], [ %31, %29 ]
%53 = add nuw nsw i64 %32, 1
%54 = sext i32 %51 to i64
%55 = icmp slt i64 %53, %54
br i1 %55, label %29, label %56
56: ; preds = %50, %18
%57 = call i32 @strlen(i8* %7)
%58 = call i32 @strcat(i8* %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%59 = call i32 @salvar(i8* %6, i8* %7, i32** %8, i32* %12)
%60 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0))
%61 = call i32 (...) @getchar()
%62 = call i32 @Matrix_Free(i32** %8, i32 1000)
br label %63
63: ; preds = %56, %15
%64 = phi i32 [ 0, %15 ], [ 1, %56 ]
ret i32 %64
}