int main(argc, argv)
int argc;
char *argv[];
{
  char name1[80], name2[80], response[80];
  int segment;
  long length, width;
  short background, hi, low, object, value;
  short **the_image, **out_image;
  if (argc < 8) {
    printf("\n\nmainseg in-file out-file hi low "
           "value operation segment"
           "\n"
           "\n\thi and low are thresholds"
           "\n\tvalue is output pixel value"
           "\n\toperation = Threshold Grow Peaks"
           " Valleys Adaptive"
           "\n\tsegment is 1 (perform segmentation) "
           "or 0 (don't)");
    printf("\n");
    exit(0);
  }
  strcpy(name1, argv[1]);
  strcpy(name2, argv[2]);
  hi = atoi(argv[3]);
  low = atoi(argv[4]);
  value = atoi(argv[5]);
  segment = atoi(argv[7]);
  if (does_not_exist(name1)) {
    printf("\nERROR input file %s does not exist", name1);
    exit(0);
  }
  get_image_size(name1, &length, &width);
  the_image = allocate_image_array(length, width);
  out_image = allocate_image_array(length, width);
  create_file_if_needed(name1, name2, out_image);
  read_image_array(name1, the_image);
  if (argv[6][0] == 't' || argv[6][0] == 'T') {
    manual_threshold_segmentation(the_image, out_image, hi, low, value, segment,
                                  length, width);
    write_image_array(name2, out_image);
  }
  if (argv[6][0] == 'g' || argv[6][0] == 'G') {
    grow(the_image, value, length, width);
    write_image_array(name2, the_image);
  }
  if (argv[6][0] == 'p' || argv[6][0] == 'P') {
    peak_threshold_segmentation(the_image, out_image, value, segment, length,
                                width);
    write_image_array(name2, out_image);
  }
  if (argv[6][0] == 'v' || argv[6][0] == 'V') {
    valley_threshold_segmentation(the_image, out_image, value, segment, length,
                                  width);
    write_image_array(name2, out_image);
  }
  if (argv[6][0] == 'a' || argv[6][0] == 'A') {
    adaptive_threshold_segmentation(the_image, out_image, value, segment,
                                    length, width);
    write_image_array(name2, out_image);
  }
  free_image_array(out_image, length);
  free_image_array(the_image, length);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x8,-0x8(%rbp)
jge    1246 <main+0x46>
lea    0xdd6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   10e0 <exit@plt>
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <strcpy@plt>
lea    -0xb0(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
mov    $0x0,%al
call   10d0 <atoi@plt>
mov    %ax,-0x11c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
mov    $0x0,%al
call   10d0 <atoi@plt>
mov    %ax,-0x11e(%rbp)
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rdi
mov    $0x0,%al
call   10d0 <atoi@plt>
mov    %ax,-0x122(%rbp)
mov    -0x10(%rbp),%rax
mov    0x38(%rax),%rdi
mov    $0x0,%al
call   10d0 <atoi@plt>
mov    %eax,-0x104(%rbp)
lea    -0x60(%rbp),%rdi
mov    $0x0,%al
call   10a0 <does_not_exist@plt>
cmp    $0x0,%eax
je     12ef <main+0xef>
lea    -0x60(%rbp),%rsi
lea    0xdf9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   10e0 <exit@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   10f0 <allocate_image_array@plt>
cltq
mov    %rax,-0x130(%rbp)
mov    -0x110(%rbp),%rdi
mov    -0x118(%rbp),%rsi
mov    $0x0,%al
call   10f0 <allocate_image_array@plt>
cltq
mov    %rax,-0x138(%rbp)
lea    -0x60(%rbp),%rdi
lea    -0xb0(%rbp),%rsi
mov    -0x138(%rbp),%rdx
mov    $0x0,%al
call   1060 <create_file_if_needed@plt>
lea    -0x60(%rbp),%rdi
mov    -0x130(%rbp),%rsi
mov    $0x0,%al
call   10c0 <read_image_array@plt>
mov    -0x10(%rbp),%rax
mov    0x30(%rax),%rax
movsbl (%rax),%eax
cmp    $0x74,%eax
je     1397 <main+0x197>
mov    -0x10(%rbp),%rax
mov    0x30(%rax),%rax
movsbl (%rax),%eax
cmp    $0x54,%eax
jne    13f5 <main+0x1f5>
mov    -0x130(%rbp),%rdi
mov    -0x138(%rbp),%rsi
movswl -0x11c(%rbp),%edx
movswl -0x11e(%rbp),%ecx
movswl -0x122(%rbp),%r8d
ff
mov    -0x104(%rbp),%r9d
mov    -0x110(%rbp),%r10
mov    -0x118(%rbp),%rax
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
mov    $0x0,%al
call   1100 <manual_threshold_segmentation@plt>
lea    -0xb0(%rbp),%rdi
mov    -0x138(%rbp),%rsi
mov    $0x0,%al
call   1070 <write_image_array@plt>
mov    -0x10(%rbp),%rax
mov    0x30(%rax),%rax
movsbl (%rax),%eax
cmp    $0x67,%eax
je     141d <main+0x21d>
mov    -0x10(%rbp),%rax
mov    0x30(%rax),%rax
movsbl (%rax),%eax
cmp    $0x47,%eax
jne    1455 <main+0x255>
mov    -0x130(%rbp),%rdi
movswl -0x122(%rbp),%esi
mov    -0x110(%rbp),%rdx
mov    -0x118(%rbp),%rcx
mov    $0x0,%al
call   1040 <grow@plt>
lea    -0xb0(%rbp),%rdi
mov    -0x130(%rbp),%rsi
mov    $0x0,%al
call   1070 <write_image_array@plt>
mov    -0x10(%rbp),%rax
mov    0x30(%rax),%rax
movsbl (%rax),%eax
cmp    $0x70,%eax
je     147d <main+0x27d>
mov    -0x10(%rbp),%rax
mov    0x30(%rax),%rax
movsbl (%rax),%eax
cmp    $0x50,%eax
jne    14c2 <main+0x2c2>
mov    -0x130(%rbp),%rdi
mov    -0x138(%rbp),%rsi
movswl -0x122(%rbp),%edx
mov    -0x104(%rbp),%ecx
mov    -0x110(%rbp),%r8
mov    -0x118(%rbp),%r9
mov    $0x0,%al
call   10b0 <peak_threshold_segmentation@plt>
lea    -0xb0(%rbp),%rdi
mov    -0x138(%rbp),%rsi
mov    $0x0,%al
call   1070 <write_image_array@plt>
mov    -0x10(%rbp),%rax
mov    0x30(%rax),%rax
movsbl (%rax),%eax
cmp    $0x76,%eax
je     14ea <main+0x2ea>
mov    -0x10(%rbp),%rax
mov    0x30(%rax),%rax
movsbl (%rax),%eax
cmp    $0x56,%eax
jne    152f <main+0x32f>
mov    -0x130(%rbp),%rdi
mov    -0x138(%rbp),%rsi
movswl -0x122(%rbp),%edx
mov    -0x104(%rbp),%ecx
mov    -0x110(%rbp),%r8
mov    -0x118(%rbp),%r9
mov    $0x0,%al
call   1110 <valley_threshold_segmentation@plt>
lea    -0xb0(%rbp),%rdi
mov    -0x138(%rbp),%rsi
mov    $0x0,%al
call   1070 <write_image_array@plt>
mov    -0x10(%rbp),%rax
mov    0x30(%rax),%rax
movsbl (%rax),%eax
cmp    $0x61,%eax
je     1557 <main+0x357>
mov    -0x10(%rbp),%rax
mov    0x30(%rax),%rax
movsbl (%rax),%eax
cmp    $0x41,%eax
jne    159c <main+0x39c>
mov    -0x130(%rbp),%rdi
mov    -0x138(%rbp),%rsi
movswl -0x122(%rbp),%edx
mov    -0x104(%rbp),%ecx
mov    -0x110(%rbp),%r8
mov    -0x118(%rbp),%r9
mov    $0x0,%al
call   1090 <adaptive_threshold_segmentation@plt>
lea    -0xb0(%rbp),%rdi
mov    -0x138(%rbp),%rsi
mov    $0x0,%al
call   1070 <write_image_array@plt>
mov    -0x138(%rbp),%rdi
mov    -0x110(%rbp),%rsi
mov    $0x0,%al
call   1120 <free_image_array@plt>
mov    -0x130(%rbp),%rdi
mov    -0x110(%rbp),%rsi
mov    $0x0,%al
call   1120 <free_image_array@plt>
mov    -0x4(%rbp),%eax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xc8,%rsp
cmp    $0x7,%edi
jle    145d <main+0x24d>
mov    %rsi,%rbx
mov    0x8(%rsi),%rsi
lea    0x70(%rsp),%rbp
mov    %rbp,%rdi
call   1040 <strcpy@plt>
mov    0x10(%rbx),%rsi
lea    0x20(%rsp),%rdi
call   1040 <strcpy@plt>
mov    0x18(%rbx),%rdi
xor    %eax,%eax
call   10e0 <atoi@plt>
mov    %eax,0x1c(%rsp)
mov    0x20(%rbx),%rdi
xor    %eax,%eax
call   10e0 <atoi@plt>
mov    %eax,0x18(%rsp)
mov    0x28(%rbx),%rdi
xor    %eax,%eax
call   10e0 <atoi@plt>
mov    %eax,%r15d
mov    0x38(%rbx),%rdi
xor    %eax,%eax
call   10e0 <atoi@plt>
mov    %eax,%r13d
mov    %rbp,%rdi
xor    %eax,%eax
call   10b0 <does_not_exist@plt>
test   %eax,%eax
jne    147c <main+0x26c>
lea    0x70(%rsp),%r14
lea    0x8(%rsp),%rsi
lea    0x10(%rsp),%rdx
mov    %r14,%rdi
xor    %eax,%eax
call   1090 <get_image_size@plt>
mov    0x8(%rsp),%rdi
mov    0x10(%rsp),%rsi
xor    %eax,%eax
call   1100 <allocate_image_array@plt>
movslq %eax,%r12
mov    0x8(%rsp),%rdi
mov    0x10(%rsp),%rsi
xor    %eax,%eax
call   1100 <allocate_image_array@plt>
movslq %eax,%rbp
lea    0x20(%rsp),%rsi
mov    %r14,%rdi
mov    %rbp,%rdx
xor    %eax,%eax
call   1070 <create_file_if_needed@plt>
mov    %r14,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   10d0 <read_image_array@plt>
mov    0x30(%rbx),%rax
mov    (%rax),%al
mov    %eax,%ecx
or     $0x20,%cl
cmp    $0x74,%cl
jne    1347 <main+0x137>
movswl 0x1c(%rsp),%edx
movswl 0x18(%rsp),%ecx
movswl %r15w,%r8d
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %r13d,%r9d
xor    %eax,%eax
push   0x10(%rsp)
push   0x10(%rsp)
call   1110 <manual_threshold_segmentation@plt>
add    $0x10,%rsp
lea    0x20(%rsp),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1080 <write_image_array@plt>
mov    0x30(%rbx),%rax
mov    (%rax),%al
mov    %eax,%ecx
or     $0x20,%cl
cmp    $0x67,%cl
jne    137e <main+0x16e>
movswl %r15w,%esi
mov    0x8(%rsp),%rdx
mov    0x10(%rsp),%rcx
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <grow@plt>
lea    0x20(%rsp),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1080 <write_image_array@plt>
mov    0x30(%rbx),%rax
mov    (%rax),%al
mov    %eax,%ecx
or     $0x20,%cl
cmp    $0x70,%cl
jne    13bb <main+0x1ab>
movswl %r15w,%edx
mov    0x8(%rsp),%r8
mov    0x10(%rsp),%r9
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %r13d,%ecx
xor    %eax,%eax
call   10c0 <peak_threshold_segmentation@plt>
lea    0x20(%rsp),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1080 <write_image_array@plt>
mov    0x30(%rbx),%rax
mov    (%rax),%al
mov    %eax,%ecx
or     $0x20,%cl
cmp    $0x76,%cl
jne    13f8 <main+0x1e8>
movswl %r15w,%edx
mov    0x8(%rsp),%r8
mov    0x10(%rsp),%r9
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %r13d,%ecx
xor    %eax,%eax
call   1120 <valley_threshold_segmentation@plt>
lea    0x20(%rsp),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1080 <write_image_array@plt>
mov    0x30(%rbx),%rax
mov    (%rax),%al
or     $0x20,%al
cmp    $0x61,%al
jne    142b <main+0x21b>
movswl %r15w,%edx
mov    0x8(%rsp),%r8
mov    0x10(%rsp),%r9
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %r13d,%ecx
xor    %eax,%eax
call   10a0 <adaptive_threshold_segmentation@plt>
lea    0x20(%rsp),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1080 <write_image_array@plt>
mov    0x8(%rsp),%rsi
mov    %rbp,%rdi
xor    %eax,%eax
call   1130 <free_image_array@plt>
mov    0x8(%rsp),%rsi
mov    %r12,%rdi
xor    %eax,%eax
call   1130 <free_image_array@plt>
xor    %eax,%eax
add    $0xc8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xb9c(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %edi,%edi
call   10f0 <exit@plt>
lea    0xc55(%rip),%rdi
lea    0x70(%rsp),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %edi,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
@.str = [216 x i8] c"\0A\0Amainseg in-file out-file hi low value operation segment\0A\0A\09hi and low are thresholds\0A\09value is output pixel value\0A\09operation = Threshold Grow Peaks Valleys Adaptive\0A\09segment is 1 (perform segmentation) or 0 (don't)\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [36 x i8] c"\0AERROR input file %s does not exist\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 i16
%14 = alloca i16
%15 = alloca i16
%16 = alloca i16
%17 = alloca i16**
%18 = alloca i16**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%19 = load i32, i32* %4
%20 = icmp slt i32 %19, 8
br i1 %20, label %21, label %24
21: ; preds = %2
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([216 x i8], [216 x i8]* @.str, i64 0, i64 0))
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
unreachable
24: ; preds = %2
%25 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i8* @strcpy(i8* %25, i8* %28)
%30 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 2
%33 = load i8*, i8** %32
%34 = call i8* @strcpy(i8* %30, i8* %33)
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 3
%37 = load i8*, i8** %36
%38 = call i32 (i8*, ...) bitcast (i32 (...)* @atoi to i32 (i8*, ...)*)(i8* %37)
%39 = trunc i32 %38 to i16
store i16 %39, i16* %13
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 4
%42 = load i8*, i8** %41
%43 = call i32 (i8*, ...) bitcast (i32 (...)* @atoi to i32 (i8*, ...)*)(i8* %42)
%44 = trunc i32 %43 to i16
store i16 %44, i16* %14
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 5
%47 = load i8*, i8** %46
%48 = call i32 (i8*, ...) bitcast (i32 (...)* @atoi to i32 (i8*, ...)*)(i8* %47)
%49 = trunc i32 %48 to i16
store i16 %49, i16* %16
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 7
%52 = load i8*, i8** %51
%53 = call i32 (i8*, ...) bitcast (i32 (...)* @atoi to i32 (i8*, ...)*)(i8* %52)
store i32 %53, i32* %9
%54 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%55 = call i32 (i8*, ...) bitcast (i32 (...)* @does_not_exist to i32 (i8*, ...)*)(i8* %54)
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %60
57: ; preds = %24
%58 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %58)
unreachable
60: ; preds = %24
%61 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%62 = call i32 (i8*, i64*, i64*, ...) bitcast (i32 (...)* @get_image_size to i32 (i8*, i64*, i64*, ...)*)(i8* %61, i64* %10, i64* %11)
%63 = load i64, i64* %10
%64 = load i64, i64* %11
%65 = call i32 (i64, i64, ...) bitcast (i32 (...)* @allocate_image_array to i32 (i64, i64, ...)*)(i64 %63, i64 %64)
%66 = sext i32 %65 to i64
%67 = inttoptr i64 %66 to i16**
store i16** %67, i16*** %17
%68 = load i64, i64* %10
%69 = load i64, i64* %11
%70 = call i32 (i64, i64, ...) bitcast (i32 (...)* @allocate_image_array to i32 (i64, i64, ...)*)(i64 %68, i64 %69)
%71 = sext i32 %70 to i64
%72 = inttoptr i64 %71 to i16**
store i16** %72, i16*** %18
%73 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%74 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%75 = load i16**, i16*** %18
%76 = call i32 (i8*, i8*, i16**, ...) bitcast (i32 (...)* @create_file_if_needed to i32 (i8*, i8*, i16**, ...)*)(i8* %73, i8* %74, i16** %75)
%77 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%78 = load i16**, i16*** %17
%79 = call i32 (i8*, i16**, ...) bitcast (i32 (...)* @read_image_array to i32 (i8*, i16**, ...)*)(i8* %77, i16** %78)
%80 = load i8**, i8*** %5
%81 = getelementptr inbounds i8*, i8** %80, i64 6
%82 = load i8*, i8** %81
%83 = getelementptr inbounds i8, i8* %82, i64 0
%84 = load i8, i8* %83
%85 = sext i8 %84 to i32
%86 = icmp eq i32 %85, 116
br i1 %86, label %95, label %87
87: ; preds = %60
%88 = load i8**, i8*** %5
%89 = getelementptr inbounds i8*, i8** %88, i64 6
%90 = load i8*, i8** %89
%91 = getelementptr inbounds i8, i8* %90, i64 0
%92 = load i8, i8* %91
%93 = sext i8 %92 to i32
%94 = icmp eq i32 %93, 84
br i1 %94, label %95, label %111
95: ; preds = %87, %60
%96 = load i16**, i16*** %17
%97 = load i16**, i16*** %18
%98 = load i16, i16* %13
%99 = sext i16 %98 to i32
%100 = load i16, i16* %14
%101 = sext i16 %100 to i32
%102 = load i16, i16* %16
%103 = sext i16 %102 to i32
%104 = load i32, i32* %9
%105 = load i64, i64* %10
%106 = load i64, i64* %11
%107 = call i32 (i16**, i16**, i32, i32, i32, i32, i64, i64, ...) bitcast (i32 (...)* @manual_threshold_segmentation to i32 (i16**, i16**, i32, i32, i32, i32, i64, i64, ...)*)(i16** %96, i16** %97, i32 %99, i32 %101, i32 %103, i32 %104, i64 %105, i64 %106)
%108 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%109 = load i16**, i16*** %18
%110 = call i32 (i8*, i16**, ...) bitcast (i32 (...)* @write_image_array to i32 (i8*, i16**, ...)*)(i8* %108, i16** %109)
br label %111
111: ; preds = %95, %87
%112 = load i8**, i8*** %5
%113 = getelementptr inbounds i8*, i8** %112, i64 6
%114 = load i8*, i8** %113
%115 = getelementptr inbounds i8, i8* %114, i64 0
%116 = load i8, i8* %115
%117 = sext i8 %116 to i32
%118 = icmp eq i32 %117, 103
br i1 %118, label %127, label %119
119: ; preds = %111
%120 = load i8**, i8*** %5
%121 = getelementptr inbounds i8*, i8** %120, i64 6
%122 = load i8*, i8** %121
%123 = getelementptr inbounds i8, i8* %122, i64 0
%124 = load i8, i8* %123
%125 = sext i8 %124 to i32
%126 = icmp eq i32 %125, 71
br i1 %126, label %127, label %137
127: ; preds = %119, %111
%128 = load i16**, i16*** %17
%129 = load i16, i16* %16
%130 = sext i16 %129 to i32
%131 = load i64, i64* %10
%132 = load i64, i64* %11
%133 = call i32 (i16**, i32, i64, i64, ...) bitcast (i32 (...)* @grow to i32 (i16**, i32, i64, i64, ...)*)(i16** %128, i32 %130, i64 %131, i64 %132)
%134 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%135 = load i16**, i16*** %17
%136 = call i32 (i8*, i16**, ...) bitcast (i32 (...)* @write_image_array to i32 (i8*, i16**, ...)*)(i8* %134, i16** %135)
br label %137
137: ; preds = %127, %119
%138 = load i8**, i8*** %5
%139 = getelementptr inbounds i8*, i8** %138, i64 6
%140 = load i8*, i8** %139
%141 = getelementptr inbounds i8, i8* %140, i64 0
%142 = load i8, i8* %141
%143 = sext i8 %142 to i32
%144 = icmp eq i32 %143, 112
br i1 %144, label %153, label %145
145: ; preds = %137
%146 = load i8**, i8*** %5
%147 = getelementptr inbounds i8*, i8** %146, i64 6
%148 = load i8*, i8** %147
%149 = getelementptr inbounds i8, i8* %148, i64 0
%150 = load i8, i8* %149
%151 = sext i8 %150 to i32
%152 = icmp eq i32 %151, 80
br i1 %152, label %153, label %165
153: ; preds = %145, %137
%154 = load i16**, i16*** %17
%155 = load i16**, i16*** %18
%156 = load i16, i16* %16
%157 = sext i16 %156 to i32
%158 = load i32, i32* %9
%159 = load i64, i64* %10
%160 = load i64, i64* %11
%161 = call i32 (i16**, i16**, i32, i32, i64, i64, ...) bitcast (i32 (...)* @peak_threshold_segmentation to i32 (i16**, i16**, i32, i32, i64, i64, ...)*)(i16** %154, i16** %155, i32 %157, i32 %158, i64 %159, i64 %160)
%162 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%163 = load i16**, i16*** %18
%164 = call i32 (i8*, i16**, ...) bitcast (i32 (...)* @write_image_array to i32 (i8*, i16**, ...)*)(i8* %162, i16** %163)
br label %165
165: ; preds = %153, %145
%166 = load i8**, i8*** %5
%167 = getelementptr inbounds i8*, i8** %166, i64 6
%168 = load i8*, i8** %167
%169 = getelementptr inbounds i8, i8* %168, i64 0
%170 = load i8, i8* %169
%171 = sext i8 %170 to i32
%172 = icmp eq i32 %171, 118
br i1 %172, label %181, label %173
173: ; preds = %165
%174 = load i8**, i8*** %5
%175 = getelementptr inbounds i8*, i8** %174, i64 6
%176 = load i8*, i8** %175
%177 = getelementptr inbounds i8, i8* %176, i64 0
%178 = load i8, i8* %177
%179 = sext i8 %178 to i32
%180 = icmp eq i32 %179, 86
br i1 %180, label %181, label %193
181: ; preds = %173, %165
%182 = load i16**, i16*** %17
%183 = load i16**, i16*** %18
%184 = load i16, i16* %16
%185 = sext i16 %184 to i32
%186 = load i32, i32* %9
%187 = load i64, i64* %10
%188 = load i64, i64* %11
%189 = call i32 (i16**, i16**, i32, i32, i64, i64, ...) bitcast (i32 (...)* @valley_threshold_segmentation to i32 (i16**, i16**, i32, i32, i64, i64, ...)*)(i16** %182, i16** %183, i32 %185, i32 %186, i64 %187, i64 %188)
%190 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%191 = load i16**, i16*** %18
%192 = call i32 (i8*, i16**, ...) bitcast (i32 (...)* @write_image_array to i32 (i8*, i16**, ...)*)(i8* %190, i16** %191)
br label %193
193: ; preds = %181, %173
%194 = load i8**, i8*** %5
%195 = getelementptr inbounds i8*, i8** %194, i64 6
%196 = load i8*, i8** %195
%197 = getelementptr inbounds i8, i8* %196, i64 0
%198 = load i8, i8* %197
%199 = sext i8 %198 to i32
%200 = icmp eq i32 %199, 97
br i1 %200, label %209, label %201
201: ; preds = %193
%202 = load i8**, i8*** %5
%203 = getelementptr inbounds i8*, i8** %202, i64 6
%204 = load i8*, i8** %203
%205 = getelementptr inbounds i8, i8* %204, i64 0
%206 = load i8, i8* %205
%207 = sext i8 %206 to i32
%208 = icmp eq i32 %207, 65
br i1 %208, label %209, label %221
209: ; preds = %201, %193
%210 = load i16**, i16*** %17
%211 = load i16**, i16*** %18
%212 = load i16, i16* %16
%213 = sext i16 %212 to i32
%214 = load i32, i32* %9
%215 = load i64, i64* %10
%216 = load i64, i64* %11
%217 = call i32 (i16**, i16**, i32, i32, i64, i64, ...) bitcast (i32 (...)* @adaptive_threshold_segmentation to i32 (i16**, i16**, i32, i32, i64, i64, ...)*)(i16** %210, i16** %211, i32 %213, i32 %214, i64 %215, i64 %216)
%218 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%219 = load i16**, i16*** %18
%220 = call i32 (i8*, i16**, ...) bitcast (i32 (...)* @write_image_array to i32 (i8*, i16**, ...)*)(i8* %218, i16** %219)
br label %221
221: ; preds = %209, %201
%222 = load i16**, i16*** %18
%223 = load i64, i64* %10
%224 = call i32 (i16**, i64, ...) bitcast (i32 (...)* @free_image_array to i32 (i16**, i64, ...)*)(i16** %222, i64 %223)
%225 = load i16**, i16*** %17
%226 = load i64, i64* %10
%227 = call i32 (i16**, i64, ...) bitcast (i32 (...)* @free_image_array to i32 (i16**, i64, ...)*)(i16** %225, i64 %226)
%228 = load i32, i32* %3
ret i32 %228
}

LLVM IR (-O2):
@.str = [216 x i8] c"\0A\0Amainseg in-file out-file hi low value operation segment\0A\0A\09hi and low are thresholds\0A\09value is output pixel value\0A\09operation = Threshold Grow Peaks Valleys Adaptive\0A\09segment is 1 (perform segmentation) or 0 (don't)\00"
@.str.2 = [36 x i8] c"\0AERROR input file %s does not exist\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 slt i32 %0, 8
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([216 x i8], [216 x i8]* @.str, i64 0, i64 0))
%14 = tail call i32 @putchar(i32 10)
tail call void @exit(i32 0)
unreachable
15: ; preds = %2
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = call i8* @strcpy(i8* %7, i8* dereferenceable(1) %17)
%19 = getelementptr inbounds i8*, i8** %1, i64 2
%20 = load i8*, i8** %19
%21 = call i8* @strcpy(i8* %8, i8* dereferenceable(1) %20)
%22 = getelementptr inbounds i8*, i8** %1, i64 3
%23 = load i8*, i8** %22
%24 = call i32 (i8*, ...) bitcast (i32 (...)* @atoi to i32 (i8*, ...)*)(i8* %23)
%25 = getelementptr inbounds i8*, i8** %1, i64 4
%26 = load i8*, i8** %25
%27 = call i32 (i8*, ...) bitcast (i32 (...)* @atoi to i32 (i8*, ...)*)(i8* %26)
%28 = getelementptr inbounds i8*, i8** %1, i64 5
%29 = load i8*, i8** %28
%30 = call i32 (i8*, ...) bitcast (i32 (...)* @atoi to i32 (i8*, ...)*)(i8* %29)
%31 = getelementptr inbounds i8*, i8** %1, i64 7
%32 = load i8*, i8** %31
%33 = call i32 (i8*, ...) bitcast (i32 (...)* @atoi to i32 (i8*, ...)*)(i8* %32)
%34 = call i32 (i8*, ...) bitcast (i32 (...)* @does_not_exist to i32 (i8*, ...)*)(i8* %7)
%35 = icmp eq i32 %34, 0
br i1 %35, label %38, label %36
36: ; preds = %15
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %7)
unreachable
38: ; preds = %15
%39 = call i32 (i8*, i64*, i64*, ...) bitcast (i32 (...)* @get_image_size to i32 (i8*, i64*, i64*, ...)*)(i8* %7, i64* %5, i64* %6)
%40 = load i64, i64* %5
%41 = load i64, i64* %6
%42 = call i32 (i64, i64, ...) bitcast (i32 (...)* @allocate_image_array to i32 (i64, i64, ...)*)(i64 %40, i64 %41)
%43 = sext i32 %42 to i64
%44 = inttoptr i64 %43 to i16**
%45 = load i64, i64* %5
%46 = load i64, i64* %6
%47 = call i32 (i64, i64, ...) bitcast (i32 (...)* @allocate_image_array to i32 (i64, i64, ...)*)(i64 %45, i64 %46)
%48 = sext i32 %47 to i64
%49 = inttoptr i64 %48 to i16**
%50 = call i32 (i8*, i8*, i16**, ...) bitcast (i32 (...)* @create_file_if_needed to i32 (i8*, i8*, i16**, ...)*)(i8* %7, i8* %8, i16** %49)
%51 = call i32 (i8*, i16**, ...) bitcast (i32 (...)* @read_image_array to i32 (i8*, i16**, ...)*)(i8* %7, i16** %44)
%52 = getelementptr inbounds i8*, i8** %1, i64 6
%53 = load i8*, i8** %52
%54 = load i8, i8* %53
switch i8 %54, label %68 [
i8 116, label %55
i8 84, label %55
]
55: ; preds = %38, %38
%56 = shl i32 %24, 16
%57 = ashr exact i32 %56, 16
%58 = shl i32 %27, 16
%59 = ashr exact i32 %58, 16
%60 = shl i32 %30, 16
%61 = ashr exact i32 %60, 16
%62 = load i64, i64* %5
%63 = load i64, i64* %6
%64 = call i32 (i16**, i16**, i32, i32, i32, i32, i64, i64, ...) bitcast (i32 (...)* @manual_threshold_segmentation to i32 (i16**, i16**, i32, i32, i32, i32, i64, i64, ...)*)(i16** %44, i16** %49, i32 %57, i32 %59, i32 %61, i32 %33, i64 %62, i64 %63)
%65 = call i32 (i8*, i16**, ...) bitcast (i32 (...)* @write_image_array to i32 (i8*, i16**, ...)*)(i8* %8, i16** %49)
%66 = load i8*, i8** %52
%67 = load i8, i8* %66
br label %68
68: ; preds = %38, %55
%69 = phi i8 [ %54, %38 ], [ %67, %55 ]
switch i8 %69, label %79 [
i8 103, label %70
i8 71, label %70
]
70: ; preds = %68, %68
%71 = shl i32 %30, 16
%72 = ashr exact i32 %71, 16
%73 = load i64, i64* %5
%74 = load i64, i64* %6
%75 = call i32 (i16**, i32, i64, i64, ...) bitcast (i32 (...)* @grow to i32 (i16**, i32, i64, i64, ...)*)(i16** %44, i32 %72, i64 %73, i64 %74)
%76 = call i32 (i8*, i16**, ...) bitcast (i32 (...)* @write_image_array to i32 (i8*, i16**, ...)*)(i8* %8, i16** %44)
%77 = load i8*, i8** %52
%78 = load i8, i8* %77
br label %79
79: ; preds = %68, %70
%80 = phi i8 [ %69, %68 ], [ %78, %70 ]
switch i8 %80, label %90 [
i8 112, label %81
i8 80, label %81
]
81: ; preds = %79, %79
%82 = shl i32 %30, 16
%83 = ashr exact i32 %82, 16
%84 = load i64, i64* %5
%85 = load i64, i64* %6
%86 = call i32 (i16**, i16**, i32, i32, i64, i64, ...) bitcast (i32 (...)* @peak_threshold_segmentation to i32 (i16**, i16**, i32, i32, i64, i64, ...)*)(i16** %44, i16** %49, i32 %83, i32 %33, i64 %84, i64 %85)
%87 = call i32 (i8*, i16**, ...) bitcast (i32 (...)* @write_image_array to i32 (i8*, i16**, ...)*)(i8* %8, i16** %49)
%88 = load i8*, i8** %52
%89 = load i8, i8* %88
br label %90
90: ; preds = %79, %81
%91 = phi i8 [ %80, %79 ], [ %89, %81 ]
switch i8 %91, label %101 [
i8 118, label %92
i8 86, label %92
]
92: ; preds = %90, %90
%93 = shl i32 %30, 16
%94 = ashr exact i32 %93, 16
%95 = load i64, i64* %5
%96 = load i64, i64* %6
%97 = call i32 (i16**, i16**, i32, i32, i64, i64, ...) bitcast (i32 (...)* @valley_threshold_segmentation to i32 (i16**, i16**, i32, i32, i64, i64, ...)*)(i16** %44, i16** %49, i32 %94, i32 %33, i64 %95, i64 %96)
%98 = call i32 (i8*, i16**, ...) bitcast (i32 (...)* @write_image_array to i32 (i8*, i16**, ...)*)(i8* %8, i16** %49)
%99 = load i8*, i8** %52
%100 = load i8, i8* %99
br label %101
101: ; preds = %90, %92
%102 = phi i8 [ %91, %90 ], [ %100, %92 ]
switch i8 %102, label %110 [
i8 97, label %103
i8 65, label %103
]
103: ; preds = %101, %101
%104 = shl i32 %30, 16
%105 = ashr exact i32 %104, 16
%106 = load i64, i64* %5
%107 = load i64, i64* %6
%108 = call i32 (i16**, i16**, i32, i32, i64, i64, ...) bitcast (i32 (...)* @adaptive_threshold_segmentation to i32 (i16**, i16**, i32, i32, i64, i64, ...)*)(i16** %44, i16** %49, i32 %105, i32 %33, i64 %106, i64 %107)
%109 = call i32 (i8*, i16**, ...) bitcast (i32 (...)* @write_image_array to i32 (i8*, i16**, ...)*)(i8* %8, i16** %49)
br label %110
110: ; preds = %101, %103
%111 = load i64, i64* %5
%112 = call i32 (i16**, i64, ...) bitcast (i32 (...)* @free_image_array to i32 (i16**, i64, ...)*)(i16** %49, i64 %111)
%113 = load i64, i64* %5
%114 = call i32 (i16**, i64, ...) bitcast (i32 (...)* @free_image_array to i32 (i16**, i64, ...)*)(i16** %44, i64 %113)
ret i32 0
}