int main(argc, argv)
int argc;
char *argv[];
{
  char in_name[80];
  char out_name[80];
  int i;
  long height, width;
  short **the_image, **out_image;
  short threshold;
  if (argc != 4) {
    printf("\nusage: halftone input-image output-image threshold\n");
    exit(0);
  }
  strcpy(in_name, argv[1]);
  strcpy(out_name, argv[2]);
  threshold = atoi(argv[3]);
  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);
  out_image = allocate_image_array(height, width);
  read_image_array(in_name, the_image);
  half_tone(the_image, out_image, threshold, 200, 0, height, width);
  write_image_array(out_name, out_image);
  free_image_array(the_image, height);
  free_image_array(out_image, height);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x4(%rbp)
je     11f1 <main+0x31>
lea    0xe1d(%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>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
mov    $0x0,%al
call   10b0 <atoi@plt>
mov    %ax,-0xda(%rbp)
lea    -0x60(%rbp),%rdi
mov    $0x0,%al
call   1090 <does_not_exist@plt>
cmp    $0x0,%eax
je     1267 <main+0xa7>
lea    -0x60(%rbp),%rsi
lea    0xdea(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe00(%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    -0xc0(%rbp),%rsi
lea    -0xc8(%rbp),%rdx
mov    $0x0,%al
call   1080 <get_image_size@plt>
mov    -0xc0(%rbp),%rdi
mov    -0xc8(%rbp),%rsi
mov    $0x0,%al
call   10d0 <allocate_image_array@plt>
cltq
mov    %rax,-0xd0(%rbp)
mov    -0xc0(%rbp),%rdi
mov    -0xc8(%rbp),%rsi
mov    $0x0,%al
call   10d0 <allocate_image_array@plt>
cltq
mov    %rax,-0xd8(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0xd0(%rbp),%rsi
mov    $0x0,%al
call   10a0 <read_image_array@plt>
mov    -0xd0(%rbp),%rdi
mov    -0xd8(%rbp),%rsi
movswl -0xda(%rbp),%edx
mov    -0xc0(%rbp),%r9
mov    -0xc8(%rbp),%rax
mov    $0xc8,%ecx
xor    %r8d,%r8d
mov    %rax,(%rsp)
mov    $0x0,%al
call   1070 <half_tone@plt>
lea    -0xb0(%rbp),%rdi
mov    -0xd8(%rbp),%rsi
mov    $0x0,%al
call   1060 <write_image_array@plt>
mov    -0xd0(%rbp),%rdi
mov    -0xc0(%rbp),%rsi
mov    $0x0,%al
call   10e0 <free_image_array@plt>
mov    -0xd8(%rbp),%rdi
mov    -0xc0(%rbp),%rsi
mov    $0x0,%al
call   10e0 <free_image_array@plt>
xor    %eax,%eax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xc0,%rsp
cmp    $0x4,%edi
jne    12ee <main+0x11e>
mov    %rsi,%rbx
mov    0x8(%rsi),%rsi
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
call   1040 <strcpy@plt>
mov    0x10(%rbx),%rsi
lea    0x70(%rsp),%rdi
call   1040 <strcpy@plt>
mov    0x18(%rbx),%rdi
xor    %eax,%eax
call   10c0 <atoi@plt>
mov    %eax,%r15d
mov    %rbp,%rdi
xor    %eax,%eax
call   10a0 <does_not_exist@plt>
test   %eax,%eax
jne    1301 <main+0x131>
lea    0x20(%rsp),%r12
lea    0x70(%rsp),%r14
mov    %r12,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <create_image_file@plt>
lea    0x10(%rsp),%rsi
lea    0x18(%rsp),%rdx
mov    %r12,%rdi
xor    %eax,%eax
call   1090 <get_image_size@plt>
mov    0x10(%rsp),%rdi
mov    0x18(%rsp),%rsi
xor    %eax,%eax
call   10e0 <allocate_image_array@plt>
movslq %eax,%rbx
mov    0x10(%rsp),%rdi
mov    0x18(%rsp),%rsi
xor    %eax,%eax
call   10e0 <allocate_image_array@plt>
movslq %eax,%rbp
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   10b0 <read_image_array@plt>
movswl %r15w,%edx
mov    0x10(%rsp),%r9
mov    0x18(%rsp),%rax
mov    %rax,(%rsp)
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0xc8,%ecx
xor    %r8d,%r8d
xor    %eax,%eax
call   1080 <half_tone@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1070 <write_image_array@plt>
mov    0x10(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   10f0 <free_image_array@plt>
mov    0x10(%rsp),%rsi
mov    %rbp,%rdi
xor    %eax,%eax
call   10f0 <free_image_array@plt>
xor    %eax,%eax
add    $0xc0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd5d(%rip),%rdi
call   1050 <puts@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
lea    0xcf8(%rip),%rdi
lea    0x20(%rsp),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xd09(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %edi,%edi
call   10d0 <exit@plt>

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

LLVM IR (-O2):
@.str.1 = [36 x i8] c"\0AERROR input file %s does not exist\00"
@.str.2 = [46 x i8] c"\0A usage: histeq input-image output-image\00"
@str = [52 x i8] c"\0Ausage: halftone input-image output-image threshold\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 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%9 = bitcast i64* %5 to i8*
%10 = bitcast i64* %6 to i8*
%11 = icmp eq i32 %0, 4
br i1 %11, label %14, label %12
12: ; preds = %2
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @str, i64 0, i64 0))
tail call void @exit(i32 0)
unreachable
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = call i8* @strcpy(i8* %7, i8* dereferenceable(1) %16)
%18 = getelementptr inbounds i8*, i8** %1, i64 2
%19 = load i8*, i8** %18
%20 = call i8* @strcpy(i8* %8, i8* dereferenceable(1) %19)
%21 = getelementptr inbounds i8*, i8** %1, i64 3
%22 = load i8*, i8** %21
%23 = call i32 (i8*, ...) bitcast (i32 (...)* @atoi to i32 (i8*, ...)*)(i8* %22)
%24 = call i32 (i8*, ...) bitcast (i32 (...)* @does_not_exist to i32 (i8*, ...)*)(i8* %7)
%25 = icmp eq i32 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %14
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0))
unreachable
29: ; preds = %14
%30 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @create_image_file to i32 (i8*, i8*, ...)*)(i8* %7, i8* %8)
%31 = call i32 (i8*, i64*, i64*, ...) bitcast (i32 (...)* @get_image_size to i32 (i8*, i64*, i64*, ...)*)(i8* %7, 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 = load i64, i64* %5
%38 = load i64, i64* %6
%39 = call i32 (i64, i64, ...) bitcast (i32 (...)* @allocate_image_array to i32 (i64, i64, ...)*)(i64 %37, i64 %38)
%40 = sext i32 %39 to i64
%41 = inttoptr i64 %40 to i16**
%42 = call i32 (i8*, i16**, ...) bitcast (i32 (...)* @read_image_array to i32 (i8*, i16**, ...)*)(i8* %7, i16** %36)
%43 = shl i32 %23, 16
%44 = ashr exact i32 %43, 16
%45 = load i64, i64* %5
%46 = load i64, i64* %6
%47 = call i32 (i16**, i16**, i32, i32, i32, i64, i64, ...) bitcast (i32 (...)* @half_tone to i32 (i16**, i16**, i32, i32, i32, i64, i64, ...)*)(i16** %36, i16** %41, i32 %44, i32 200, i32 0, i64 %45, i64 %46)
%48 = call i32 (i8*, i16**, ...) bitcast (i32 (...)* @write_image_array to i32 (i8*, i16**, ...)*)(i8* %8, i16** %41)
%49 = load i64, i64* %5
%50 = call i32 (i16**, i64, ...) bitcast (i32 (...)* @free_image_array to i32 (i16**, i64, ...)*)(i16** %36, i64 %49)
%51 = load i64, i64* %5
%52 = call i32 (i16**, i64, ...) bitcast (i32 (...)* @free_image_array to i32 (i16**, i64, ...)*)(i16** %41, i64 %51)
ret i32 0
}