#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ perror(char *);
int sort(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcmp(char *, char *);
int main(int argc, char **argv) {
  FILE *file = NULL;
  if (argc < 2)
    file = stdin;
  int i, ret = 0;
  for (i = 1; i < argc || file; i++, file = NULL) {
    if (!file) {
      if (!strcmp(argv[i], "-"))
        file = stdin;
      else
        file = fopen(argv[i], "r");
    }
    if (!file) {
      perror("sort");
      ret = 1;
      continue;
    }
    int err = sort(file, stdout);
    if (file != stdin)
      fclose(file);
    if (err < 0) {
      perror("sort");
      ret = 1;
      continue;
    }
  }
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1186 <main+0x36>
mov    0x2e69(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%ecx
mov    $0x1,%al
cmp    -0x8(%rbp),%ecx
mov    %al,-0x25(%rbp)
jl     11b0 <main+0x60>
cmpq   $0x0,-0x18(%rbp)
setne  %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    11c0 <main+0x70>
jmp    12b2 <main+0x162>
cmpq   $0x0,-0x18(%rbp)
jne    1220 <main+0xd0>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe22(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11ff <main+0xaf>
mov    0x2df5(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    121b <main+0xcb>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xdf0(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
jmp    1220 <main+0xd0>
cmpq   $0x0,-0x18(%rbp)
jne    1243 <main+0xf3>
lea    0xdd2(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x20(%rbp)
jmp    129c <main+0x14c>
mov    -0x18(%rbp),%rdi
mov    0x2d8a(%rip),%rax
mov    (%rax),%esi
call   1040 <sort@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2d85(%rip),%rcx
cmp    (%rcx),%rax
je     1275 <main+0x125>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
cmpl   $0x0,-0x24(%rbp)
jge    1297 <main+0x147>
lea    0xd7e(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x20(%rbp)
jmp    129c <main+0x14c>
jmp    129c <main+0x14c>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
movq   $0x0,-0x18(%rbp)
jmp    1194 <main+0x44>
mov    -0x20(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%r15d
mov    0x2e80(%rip),%rax
mov    (%rax),%rbp
cmp    $0x1,%edi
jg     1181 <main+0x31>
movl   $0x0,0x4(%rsp)
test   %rbp,%rbp
je     1209 <main+0xb9>
cmp    $0x3,%r15d
mov    $0x2,%r12d
cmovge %r15d,%r12d
cmp    $0x1,%r15d
jg     119a <main+0x4a>
test   %rbp,%rbp
jne    11cc <main+0x7c>
mov    0x8(%rbx),%r13
lea    0xe5b(%rip),%rsi
mov    %r13,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     11c3 <main+0x73>
lea    0xe4a(%rip),%rsi
mov    %r13,%rdi
call   1060 <fopen@plt>
mov    %rax,%rbp
test   %rbp,%rbp
je     12c8 <main+0x178>
mov    0x2e05(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   1040 <sort@plt>
mov    %eax,%r13d
mov    0x2e01(%rip),%rax
cmp    (%rax),%rbp
je     11f4 <main+0xa4>
mov    %rbp,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
test   %r13d,%r13d
js     12c8 <main+0x178>
mov    %eax,0x4(%rsp)
cmp    $0x3,%r15d
jge    121c <main+0xcc>
mov    0x4(%rsp),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x2,%r14d
lea    0xdd7(%rip),%r13
jmp    123e <main+0xee>
nopl   0x0(%rax,%rax,1)
test   %r15d,%r15d
js     12af <main+0x15f>
add    $0x1,%r14
cmp    %r14,%r12
je     1209 <main+0xb9>
mov    (%rbx,%r14,8),%rbp
mov    %rbp,%rdi
mov    %r13,%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     12a0 <main+0x150>
mov    %rbp,%rdi
lea    0xda7(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbp
test   %rbp,%rbp
je     12af <main+0x15f>
mov    0x2d69(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   1040 <sort@plt>
mov    %eax,%r15d
mov    0x2d65(%rip),%rax
cmp    (%rax),%rbp
je     1230 <main+0xe0>
mov    %rbp,%rdi
call   1030 <fclose@plt>
jmp    1230 <main+0xe0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x2d41(%rip),%rax
mov    (%rax),%rbp
test   %rbp,%rbp
jne    1268 <main+0x118>
lea    0xd4e(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,0x4(%rsp)
jmp    1235 <main+0xe5>
lea    0xd35(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%eax
jmp    11ff <main+0xaf>

LLVM IR (-O0):
@stdin = global i32* null
@.str = [2 x i8] c"-\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [5 x i8] c"sort\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %6
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = load i32*, i32** @stdin
store i32* %13, i32** %6
br label %14
14: ; preds = %12, %2
store i32 0, i32* %8
store i32 1, i32* %7
br label %15
15: ; preds = %66, %14
%16 = load i32, i32* %7
%17 = load i32, i32* %4
%18 = icmp slt i32 %16, %17
br i1 %18, label %22, label %19
19: ; preds = %15
%20 = load i32*, i32** %6
%21 = icmp ne i32* %20, null
br label %22
22: ; preds = %19, %15
%23 = phi i1 [ true, %15 ], [ %21, %19 ]
br i1 %23, label %24, label %69
24: ; preds = %22
%25 = load i32*, i32** %6
%26 = icmp ne i32* %25, null
br i1 %26, label %45, label %27
27: ; preds = %24
%28 = load i8**, i8*** %5
%29 = load i32, i32* %7
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8*, i8** %28, i64 %30
%32 = load i8*, i8** %31
%33 = call i32 @strcmp(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%34 = icmp ne i32 %33, 0
br i1 %34, label %37, label %35
35: ; preds = %27
%36 = load i32*, i32** @stdin
store i32* %36, i32** %6
br label %44
37: ; preds = %27
%38 = load i8**, i8*** %5
%39 = load i32, i32* %7
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8*, i8** %38, i64 %40
%42 = load i8*, i8** %41
%43 = call i32* @fopen(i8* %42, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %43, i32** %6
br label %44
44: ; preds = %37, %35
br label %45
45: ; preds = %44, %24
%46 = load i32*, i32** %6
%47 = icmp ne i32* %46, null
br i1 %47, label %50, label %48
48: ; preds = %45
%49 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %8
br label %66
50: ; preds = %45
%51 = load i32*, i32** %6
%52 = load i32, i32* @stdout
%53 = call i32 @sort(i32* %51, i32 %52)
store i32 %53, i32* %9
%54 = load i32*, i32** %6
%55 = load i32*, i32** @stdin
%56 = icmp ne i32* %54, %55
br i1 %56, label %57, label %60
57: ; preds = %50
%58 = load i32*, i32** %6
%59 = call i32 @fclose(i32* %58)
br label %60
60: ; preds = %57, %50
%61 = load i32, i32* %9
%62 = icmp slt i32 %61, 0
br i1 %62, label %63, label %65
63: ; preds = %60
%64 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %8
br label %66
65: ; preds = %60
br label %66
66: ; preds = %65, %63, %48
%67 = load i32, i32* %7
%68 = add nsw i32 %67, 1
store i32 %68, i32* %7
store i32* null, i32** %6
br label %15
69: ; preds = %22
%70 = load i32, i32* %8
ret i32 %70
}

LLVM IR (-O2):
@stdin = global i32* null
@.str = [2 x i8] c"-\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [5 x i8] c"sort\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32*, i32** @stdin
%4 = icmp sgt i32 %0, 1
%5 = icmp ne i32* %3, null
%6 = select i1 %4, i1 true, i1 %5
br i1 %6, label %7, label %66
7: ; preds = %2
%8 = icmp slt i32 %0, 2
%9 = select i1 %8, i1 %5, i1 false
%10 = call i32 @llvm.smax.i32(i32 %0, i32 2)
%11 = zext i32 %10 to i64
br i1 %9, label %22, label %12
12: ; preds = %7
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i32 @strcmp(i8* dereferenceable(1) %14, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i32 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %12
%18 = tail call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %12, %17
%20 = phi i32* [ %18, %17 ], [ %3, %12 ]
%21 = icmp eq i32* %20, null
br i1 %21, label %32, label %22
22: ; preds = %19, %7
%23 = phi i32* [ %20, %19 ], [ %3, %7 ]
%24 = load i32, i32* @stdout
%25 = tail call i32 @sort(i32* %23, i32 %24)
%26 = load i32*, i32** @stdin
%27 = icmp eq i32* %23, %26
br i1 %27, label %30, label %28
28: ; preds = %22
%29 = tail call i32 @fclose(i32* %23)
br label %30
30: ; preds = %28, %22
%31 = icmp slt i32 %25, 0
br i1 %31, label %32, label %34
32: ; preds = %30, %19
%33 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %34
34: ; preds = %32, %30
%35 = phi i32 [ 0, %30 ], [ 1, %32 ]
%36 = icmp slt i32 %0, 3
br i1 %36, label %66, label %37
37: ; preds = %34, %62
%38 = phi i64 [ %64, %62 ], [ 2, %34 ]
%39 = phi i32 [ %63, %62 ], [ %35, %34 ]
%40 = getelementptr inbounds i8*, i8** %1, i64 %38
%41 = load i8*, i8** %40
%42 = tail call i32 @strcmp(i8* dereferenceable(1) %41, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %37
%45 = load i32*, i32** @stdin
br label %48
46: ; preds = %37
%47 = tail call i32* @fopen(i8* %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %48
48: ; preds = %44, %46
%49 = phi i32* [ %47, %46 ], [ %45, %44 ]
%50 = icmp eq i32* %49, null
br i1 %50, label %60, label %51
51: ; preds = %48
%52 = load i32, i32* @stdout
%53 = tail call i32 @sort(i32* %49, i32 %52)
%54 = load i32*, i32** @stdin
%55 = icmp eq i32* %49, %54
br i1 %55, label %58, label %56
56: ; preds = %51
%57 = tail call i32 @fclose(i32* %49)
br label %58
58: ; preds = %56, %51
%59 = icmp slt i32 %53, 0
br i1 %59, label %60, label %62
60: ; preds = %58, %48
%61 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %62
62: ; preds = %60, %58
%63 = phi i32 [ %39, %58 ], [ 1, %60 ]
%64 = add nuw nsw i64 %38, 1
%65 = icmp eq i64 %64, %11
br i1 %65, label %66, label %37
66: ; preds = %62, %34, %2
%67 = phi i32 [ 0, %2 ], [ %35, %34 ], [ %63, %62 ]
ret i32 %67
}