#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*/ catsort_help();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sort_sdss(char *, char *, char *, int);
int /*<<< orphan*/ sort_secat(char *, char *, char *, char *, int);
int sscanf(char *, char *, int *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
int main(int argc, char *argv[]) {
  int no_error = 1;
  int format;
  char catfile[1000];
  char posfile[1000];
  char outfile[1000];
  char calcmethod[1000];
  if (argc < 4) {
    catsort_help();
    return 1;
  }
  printf("\n");
  strcpy(posfile, argv[1]);
  strcpy(catfile, argv[2]);
  strcpy(outfile, argv[3]);
  strcpy(calcmethod, argv[4]);
  if (argc == 6) {
    if (sscanf(argv[5], "%d", &format) != 1)
      no_error = 0;
  } else
    format = 6;
  if (no_error) {
    switch (format) {
    case 11:
    case 12:
      if (sort_sdss(catfile, posfile, outfile, format))
        no_error = 1;
      break;
    default:
      if (sort_secat(catfile, posfile, outfile, calcmethod, format))
        no_error = 0;
    }
  }
  if (no_error) {
    printf("\nProgram catsort finished.\n\n");
    return 0;
  } else {
    fprintf(stderr, "\nERROR.  Exiting catsort.\n\n");
    return 1;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xfd0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    11ad <main+0x3d>
mov    $0x0,%al
call   1080 <catsort_help@plt>
movl   $0x1,-0x4(%rbp)
jmp    1314 <main+0x1a4>
lea    0xe6a(%rip),%rdi
call   1060 <printf@plt>
lea    -0x7f0(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <strcpy@plt>
lea    -0x400(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1030 <strcpy@plt>
lea    -0xbe0(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
call   1030 <strcpy@plt>
lea    -0xfd0(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rsi
call   1030 <strcpy@plt>
cmpl   $0x6,-0x8(%rbp)
jne    1240 <main+0xd0>
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rdi
lea    0xdde(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1090 <sscanf@plt>
cmp    $0x1,%eax
je     123b <main+0xcb>
movl   $0x0,-0x14(%rbp)
jmp    1247 <main+0xd7>
movl   $0x6,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     12d6 <main+0x166>
mov    -0x18(%rbp),%eax
add    $0xfffffff5,%eax
sub    $0x1,%eax
ja     1297 <main+0x127>
jmp    1265 <main+0xf5>
lea    -0x400(%rbp),%rdi
lea    -0x7f0(%rbp),%rsi
lea    -0xbe0(%rbp),%rdx
mov    -0x18(%rbp),%ecx
call   1040 <sort_sdss@plt>
cmp    $0x0,%eax
je     1292 <main+0x122>
movl   $0x1,-0x14(%rbp)
jmp    12d1 <main+0x161>
lea    -0x400(%rbp),%rdi
lea    -0x7f0(%rbp),%rsi
lea    -0xbe0(%rbp),%rdx
lea    -0xfd0(%rbp),%rcx
mov    -0x18(%rbp),%r8d
call   1050 <sort_secat@plt>
cmp    $0x0,%eax
je     12cc <main+0x15c>
movl   $0x0,-0x14(%rbp)
jmp    12d1 <main+0x161>
jmp    12d6 <main+0x166>
cmpl   $0x0,-0x14(%rbp)
je     12f8 <main+0x188>
lea    0xd1c(%rip),%rdi
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1314 <main+0x1a4>
mov    0x2ce1(%rip),%rax
mov    (%rax),%edi
lea    0xd18(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xfd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0xfc8,%rsp
cmp    $0x3,%edi
jg     119a <main+0x1a>
xor    %eax,%eax
call   1090 <catsort_help@plt>
jmp    127f <main+0xff>
mov    %rsi,%rbx
mov    %edi,%ebp
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x8(%rbx),%rsi
lea    0x400(%rsp),%rdi
call   1040 <strcpy@plt>
mov    0x10(%rbx),%rsi
lea    0x7f0(%rsp),%rdi
call   1040 <strcpy@plt>
mov    0x18(%rbx),%rsi
lea    0x10(%rsp),%rdi
call   1040 <strcpy@plt>
mov    0x20(%rbx),%rsi
lea    0xbe0(%rsp),%rdi
call   1040 <strcpy@plt>
cmp    $0x6,%ebp
jne    1236 <main+0xb6>
mov    0x28(%rbx),%rdi
lea    0xe06(%rip),%rsi
lea    0xc(%rsp),%rdx
call   10a0 <sscanf@plt>
cmp    $0x1,%eax
jne    126a <main+0xea>
mov    0xc(%rsp),%r8d
lea    -0xb(%r8),%eax
cmp    $0x1,%eax
ja     1244 <main+0xc4>
lea    0x7f0(%rsp),%rdi
lea    0x400(%rsp),%rsi
lea    0x10(%rsp),%rdx
mov    %r8d,%ecx
call   1050 <sort_sdss@plt>
jmp    128e <main+0x10e>
movl   $0x6,0xc(%rsp)
mov    $0x6,%r8d
lea    0x7f0(%rsp),%rdi
lea    0x400(%rsp),%rsi
lea    0x10(%rsp),%rdx
lea    0xbe0(%rsp),%rcx
call   1070 <sort_secat@plt>
test   %eax,%eax
je     128e <main+0x10e>
mov    0x2d6f(%rip),%rax
mov    (%rax),%edi
lea    0xd89(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%eax
add    $0xfc8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xd8a(%rip),%rdi
call   1060 <puts@plt>
xor    %eax,%eax
jmp    1284 <main+0x104>

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [29 x i8] c"\0AProgram catsort finished.\0A\0A\00"
@stderr = global i32 0
@.str.3 = [28 x i8] c"\0AERROR. Exiting catsort.\0A\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [1000 x i8]
%9 = alloca [1000 x i8]
%10 = alloca [1000 x i8]
%11 = alloca [1000 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %6
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 4
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 (...) @catsort_help()
store i32 1, i32* %3
br label %82
16: ; preds = %2
%17 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%18 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 0
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @strcpy(i8* %18, i8* %21)
%23 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 2
%26 = load i8*, i8** %25
%27 = call i32 @strcpy(i8* %23, i8* %26)
%28 = getelementptr inbounds [1000 x i8], [1000 x i8]* %10, i64 0, i64 0
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 3
%31 = load i8*, i8** %30
%32 = call i32 @strcpy(i8* %28, i8* %31)
%33 = getelementptr inbounds [1000 x i8], [1000 x i8]* %11, i64 0, i64 0
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 4
%36 = load i8*, i8** %35
%37 = call i32 @strcpy(i8* %33, i8* %36)
%38 = load i32, i32* %4
%39 = icmp eq i32 %38, 6
br i1 %39, label %40, label %48
40: ; preds = %16
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 5
%43 = load i8*, i8** %42
%44 = call i32 @sscanf(i8* %43, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %7)
%45 = icmp ne i32 %44, 1
br i1 %45, label %46, label %47
46: ; preds = %40
store i32 0, i32* %6
br label %47
47: ; preds = %46, %40
br label %49
48: ; preds = %16
store i32 6, i32* %7
br label %49
49: ; preds = %48, %47
%50 = load i32, i32* %6
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %74
52: ; preds = %49
%53 = load i32, i32* %7
switch i32 %53, label %63 [
i32 11, label %54
i32 12, label %54
]
54: ; preds = %52, %52
%55 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%56 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 0
%57 = getelementptr inbounds [1000 x i8], [1000 x i8]* %10, i64 0, i64 0
%58 = load i32, i32* %7
%59 = call i32 @sort_sdss(i8* %55, i8* %56, i8* %57, i32 %58)
%60 = icmp ne i32 %59, 0
br i1 %60, label %61, label %62
61: ; preds = %54
store i32 1, i32* %6
br label %62
62: ; preds = %61, %54
br label %73
63: ; preds = %52
%64 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%65 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 0
%66 = getelementptr inbounds [1000 x i8], [1000 x i8]* %10, i64 0, i64 0
%67 = getelementptr inbounds [1000 x i8], [1000 x i8]* %11, i64 0, i64 0
%68 = load i32, i32* %7
%69 = call i32 @sort_secat(i8* %64, i8* %65, i8* %66, i8* %67, i32 %68)
%70 = icmp ne i32 %69, 0
br i1 %70, label %71, label %72
71: ; preds = %63
store i32 0, i32* %6
br label %72
72: ; preds = %71, %63
br label %73
73: ; preds = %72, %62
br label %74
74: ; preds = %73, %49
%75 = load i32, i32* %6
%76 = icmp ne i32 %75, 0
br i1 %76, label %77, label %79
77: ; preds = %74
%78 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %82
79: ; preds = %74
%80 = load i32, i32* @stderr
%81 = call i32 @fprintf(i32 %80, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %82
82: ; preds = %79, %77, %14
%83 = load i32, i32* %3
ret i32 %83
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.3 = [28 x i8] c"\0AERROR. Exiting catsort.\0A\0A\00"
@str = [28 x i8] c"\0AProgram catsort finished.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca [1000 x i8]
%5 = alloca [1000 x i8]
%6 = alloca [1000 x i8]
%7 = alloca [1000 x i8]
%8 = bitcast i32* %3 to i8*
%9 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%10 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%11 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%12 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 0
%13 = icmp slt i32 %0, 4
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = tail call i32 (...) @catsort_help()
br label %52
16: ; preds = %2
%17 = tail call i32 @putchar(i32 10)
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @strcpy(i8* %10, i8* %19)
%21 = getelementptr inbounds i8*, i8** %1, i64 2
%22 = load i8*, i8** %21
%23 = call i32 @strcpy(i8* %9, i8* %22)
%24 = getelementptr inbounds i8*, i8** %1, i64 3
%25 = load i8*, i8** %24
%26 = call i32 @strcpy(i8* %11, i8* %25)
%27 = getelementptr inbounds i8*, i8** %1, i64 4
%28 = load i8*, i8** %27
%29 = call i32 @strcpy(i8* %12, i8* %28)
%30 = icmp eq i32 %0, 6
br i1 %30, label %31, label %36
31: ; preds = %16
%32 = getelementptr inbounds i8*, i8** %1, i64 5
%33 = load i8*, i8** %32
%34 = call i32 @sscanf(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%35 = icmp eq i32 %34, 1
br i1 %35, label %37, label %49
36: ; preds = %16
store i32 6, i32* %3
br label %43
37: ; preds = %31
%38 = load i32, i32* %3
%39 = add i32 %38, -11
%40 = icmp ult i32 %39, 2
br i1 %40, label %41, label %43
41: ; preds = %37
%42 = call i32 @sort_sdss(i8* %9, i8* %10, i8* %11, i32 %38)
br label %47
43: ; preds = %36, %37
%44 = phi i32 [ 6, %36 ], [ %38, %37 ]
%45 = call i32 @sort_secat(i8* %9, i8* %10, i8* %11, i8* %12, i32 %44)
%46 = icmp eq i32 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %41, %43
%48 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
br label %52
49: ; preds = %31, %43
%50 = load i32, i32* @stderr
%51 = call i32 @fprintf(i32 %50, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
br label %52
52: ; preds = %49, %47, %14
%53 = phi i32 [ 1, %14 ], [ 0, %47 ], [ 1, %49 ]
ret i32 %53
}