int main(argc, argv)
int argc;
char *argv[];
{
  char in_name[80];
  char out_name[80];
  char response[80];
  int i;
  long height, width;
  short **the_image;
  unsigned long histogram[255 + 1];
  if (argc < 3) {
    printf("\n   usage: histeq input-image output-image");
    printf("\n\n");
    exit(0);
  }
  strcpy(in_name, argv[1]);
  strcpy(out_name, argv[2]);
  if (does_not_exist(in_name)) {
    printf("\nERROR input file %s does not exist", in_name);
    printf("\n      "
           "usage: histeq input-image output-image");
    exit(0);
  }
  create_image_file(in_name, out_name);
  get_image_size(in_name, &height, &width);
  the_image = allocate_image_array(height, width);
  read_image_array(in_name, the_image);
  for (i = 0; i < 255 + 1; i++)
    histogram[i] = 0;
  calculate_histogram(the_image, histogram, height, width);
  perform_histogram_equalization(the_image, histogram, 256, 250, height, width);
  write_image_array(out_name, the_image);
  free_image_array(the_image, height);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x920,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    1206 <main+0x46>
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1040 <strcpy@plt>
lea    -0xb0(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1040 <strcpy@plt>
lea    -0x60(%rbp),%rdi
mov    $0x0,%al
call   10a0 <does_not_exist@plt>
cmp    $0x0,%eax
je     1266 <main+0xa6>
lea    -0x60(%rbp),%rsi
lea    0xde4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xdfa(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
lea    -0x60(%rbp),%rdi
lea    -0xb0(%rbp),%rsi
mov    $0x0,%al
call   1030 <create_image_file@plt>
lea    -0x60(%rbp),%rdi
lea    -0x110(%rbp),%rsi
lea    -0x118(%rbp),%rdx
mov    $0x0,%al
call   1080 <get_image_size@plt>
mov    -0x110(%rbp),%rdi
mov    -0x118(%rbp),%rsi
mov    $0x0,%al
call   10d0 <allocate_image_array@plt>
cltq
mov    %rax,-0x120(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x120(%rbp),%rsi
mov    $0x0,%al
call   10b0 <read_image_array@plt>
movl   $0x0,-0x104(%rbp)
cmpl   $0x100,-0x104(%rbp)
jge    1302 <main+0x142>
movslq -0x104(%rbp),%rax
movq   $0x0,-0x920(%rbp,%rax,8)
mov    -0x104(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x104(%rbp)
jmp    12cb <main+0x10b>
mov    -0x120(%rbp),%rdi
lea    -0x920(%rbp),%rsi
mov    -0x110(%rbp),%rdx
mov    -0x118(%rbp),%rcx
mov    $0x0,%al
call   1070 <calculate_histogram@plt>
mov    -0x120(%rbp),%rdi
lea    -0x920(%rbp),%rsi
mov    -0x110(%rbp),%r8
mov    -0x118(%rbp),%r9
mov    $0x100,%edx
mov    $0xfa,%ecx
mov    $0x0,%al
call   1090 <perform_histogram_equalization@plt>
lea    -0xb0(%rbp),%rdi
mov    -0x120(%rbp),%rsi
mov    $0x0,%al
call   1060 <write_image_array@plt>
mov    -0x120(%rbp),%rdi
mov    -0x110(%rbp),%rsi
mov    $0x0,%al
call   10e0 <free_image_array@plt>
mov    -0x4(%rbp),%eax
add    $0x920,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x8b0,%rsp
cmp    $0x2,%edi
jle    12e9 <main+0x109>
mov    %rsi,%rbx
mov    0x8(%rsi),%rsi
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   1040 <strcpy@plt>
mov    0x10(%rbx),%rsi
lea    0x60(%rsp),%rdi
call   1040 <strcpy@plt>
mov    %r14,%rdi
xor    %eax,%eax
call   10c0 <does_not_exist@plt>
test   %eax,%eax
jne    130a <main+0x12a>
lea    0x10(%rsp),%r15
lea    0x60(%rsp),%r14
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <create_image_file@plt>
mov    %rsp,%rsi
lea    0x8(%rsp),%rdx
mov    %r15,%rdi
xor    %eax,%eax
call   10a0 <get_image_size@plt>
mov    (%rsp),%rdi
mov    0x8(%rsp),%rsi
xor    %eax,%eax
call   10f0 <allocate_image_array@plt>
movslq %eax,%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   10d0 <read_image_array@plt>
lea    0xb0(%rsp),%r15
mov    $0x800,%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1070 <memset@plt>
mov    (%rsp),%rdx
mov    0x8(%rsp),%rcx
mov    %rbx,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1090 <calculate_histogram@plt>
mov    (%rsp),%r8
mov    0x8(%rsp),%r9
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x100,%edx
mov    $0xfa,%ecx
xor    %eax,%eax
call   10b0 <perform_histogram_equalization@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <write_image_array@plt>
mov    (%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1100 <free_image_array@plt>
xor    %eax,%eax
add    $0x8b0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xd10(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xd7f(%rip),%rdi
call   1050 <puts@plt>
xor    %edi,%edi
call   10e0 <exit@plt>
lea    0xd1a(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xd2b(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %edi,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
@.str = [43 x i8] c"\0A usage: histeq input-image output-image\00"
@.str.1 = [3 x i8] c"\0A\0A\00"
@.str.2 = [36 x i8] c"\0AERROR input file %s does not exist\00"
@.str.3 = [46 x i8] c"\0A usage: histeq input-image output-image\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [80 x i8]
%7 = alloca [80 x i8]
%8 = alloca [80 x i8]
%9 = alloca i32
%10 = alloca i64
%11 = alloca i64
%12 = alloca i16**
%13 = alloca [256 x i64]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 3
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
unreachable
19: ; preds = %2
%20 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i8* @strcpy(i8* %20, i8* %23)
%25 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = call i8* @strcpy(i8* %25, i8* %28)
%30 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%31 = call i32 (i8*, ...) bitcast (i32 (...)* @does_not_exist to i32 (i8*, ...)*)(i8* %30)
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %19
%34 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %34)
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0))
unreachable
37: ; preds = %19
%38 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%39 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%40 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @create_image_file to i32 (i8*, i8*, ...)*)(i8* %38, i8* %39)
%41 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%42 = call i32 (i8*, i64*, i64*, ...) bitcast (i32 (...)* @get_image_size to i32 (i8*, i64*, i64*, ...)*)(i8* %41, i64* %10, i64* %11)
%43 = load i64, i64* %10
%44 = load i64, i64* %11
%45 = call i32 (i64, i64, ...) bitcast (i32 (...)* @allocate_image_array to i32 (i64, i64, ...)*)(i64 %43, i64 %44)
%46 = sext i32 %45 to i64
%47 = inttoptr i64 %46 to i16**
store i16** %47, i16*** %12
%48 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%49 = load i16**, i16*** %12
%50 = call i32 (i8*, i16**, ...) bitcast (i32 (...)* @read_image_array to i32 (i8*, i16**, ...)*)(i8* %48, i16** %49)
store i32 0, i32* %9
br label %51
51: ; preds = %58, %37
%52 = load i32, i32* %9
%53 = icmp slt i32 %52, 256
br i1 %53, label %54, label %61
54: ; preds = %51
%55 = load i32, i32* %9
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [256 x i64], [256 x i64]* %13, i64 0, i64 %56
store i64 0, i64* %57
br label %58
58: ; preds = %54
%59 = load i32, i32* %9
%60 = add nsw i32 %59, 1
store i32 %60, i32* %9
br label %51
61: ; preds = %51
%62 = load i16**, i16*** %12
%63 = getelementptr inbounds [256 x i64], [256 x i64]* %13, i64 0, i64 0
%64 = load i64, i64* %10
%65 = load i64, i64* %11
%66 = call i32 (i16**, i64*, i64, i64, ...) bitcast (i32 (...)* @calculate_histogram to i32 (i16**, i64*, i64, i64, ...)*)(i16** %62, i64* %63, i64 %64, i64 %65)
%67 = load i16**, i16*** %12
%68 = getelementptr inbounds [256 x i64], [256 x i64]* %13, i64 0, i64 0
%69 = load i64, i64* %10
%70 = load i64, i64* %11
%71 = call i32 (i16**, i64*, i32, i32, i64, i64, ...) bitcast (i32 (...)* @perform_histogram_equalization to i32 (i16**, i64*, i32, i32, i64, i64, ...)*)(i16** %67, i64* %68, i32 256, i32 250, i64 %69, i64 %70)
%72 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%73 = load i16**, i16*** %12
%74 = call i32 (i8*, i16**, ...) bitcast (i32 (...)* @write_image_array to i32 (i8*, i16**, ...)*)(i8* %72, i16** %73)
%75 = load i16**, i16*** %12
%76 = load i64, i64* %10
%77 = call i32 (i16**, i64, ...) bitcast (i32 (...)* @free_image_array to i32 (i16**, i64, ...)*)(i16** %75, i64 %76)
%78 = load i32, i32* %3
ret i32 %78
}

LLVM IR (-O2):
@.str = [43 x i8] c"\0A usage: histeq input-image output-image\00"
@.str.2 = [36 x i8] c"\0AERROR input file %s does not exist\00"
@.str.3 = [46 x i8] c"\0A usage: histeq input-image output-image\00"
@str = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [80 x i8]
%4 = alloca [80 x i8]
%5 = alloca i64
%6 = alloca i64
%7 = alloca [256 x i64]
%8 = bitcast [256 x i64]* %7 to i8*
%9 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%10 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%11 = bitcast i64* %5 to i8*
%12 = bitcast i64* %6 to i8*
%13 = icmp slt i32 %0, 3
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
tail call void @exit(i32 0)
unreachable
17: ; preds = %2
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = call i8* @strcpy(i8* %9, i8* dereferenceable(1) %19)
%21 = getelementptr inbounds i8*, i8** %1, i64 2
%22 = load i8*, i8** %21
%23 = call i8* @strcpy(i8* %10, i8* dereferenceable(1) %22)
%24 = call i32 (i8*, ...) bitcast (i32 (...)* @does_not_exist to i32 (i8*, ...)*)(i8* %9)
%25 = icmp eq i32 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %17
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0))
unreachable
29: ; preds = %17
%30 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @create_image_file to i32 (i8*, i8*, ...)*)(i8* %9, i8* %10)
%31 = call i32 (i8*, i64*, i64*, ...) bitcast (i32 (...)* @get_image_size to i32 (i8*, i64*, i64*, ...)*)(i8* %9, i64* %5, i64* %6)
%32 = load i64, i64* %5
%33 = load i64, i64* %6
%34 = call i32 (i64, i64, ...) bitcast (i32 (...)* @allocate_image_array to i32 (i64, i64, ...)*)(i64 %32, i64 %33)
%35 = sext i32 %34 to i64
%36 = inttoptr i64 %35 to i16**
%37 = call i32 (i8*, i16**, ...) bitcast (i32 (...)* @read_image_array to i32 (i8*, i16**, ...)*)(i8* %9, i16** %36)
%38 = getelementptr inbounds [256 x i64], [256 x i64]* %7, i64 0, i64 0
%39 = load i64, i64* %5
%40 = load i64, i64* %6
%41 = call i32 (i16**, i64*, i64, i64, ...) bitcast (i32 (...)* @calculate_histogram to i32 (i16**, i64*, i64, i64, ...)*)(i16** %36, i64* %38, i64 %39, i64 %40)
%42 = load i64, i64* %5
%43 = load i64, i64* %6
%44 = call i32 (i16**, i64*, i32, i32, i64, i64, ...) bitcast (i32 (...)* @perform_histogram_equalization to i32 (i16**, i64*, i32, i32, i64, i64, ...)*)(i16** %36, i64* %38, i32 256, i32 250, i64 %42, i64 %43)
%45 = call i32 (i8*, i16**, ...) bitcast (i32 (...)* @write_image_array to i32 (i8*, i16**, ...)*)(i8* %10, i16** %36)
%46 = load i64, i64* %5
%47 = call i32 (i16**, i64, ...) bitcast (i32 (...)* @free_image_array to i32 (i16**, i64, ...)*)(i16** %36, i64 %46)
ret i32 0
}