#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 atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
void sort(const char *input, const char *output) {
  FILE *in = fopen(input, "r");
  FILE *out = fopen(output, "w");
  char *bitmap = (char *)malloc(1250000);
  char line[32];
  int n = 0;
  memset(bitmap, 0, 1250000);
  while (fgets(line, 31, in) != NULL) {
    n = atoi(line);
    bitmap[n / 8] |= (1 << (7 - n % 8));
  }
  for (n = 0; n < 1250000 * 8; n++) {
    if (bitmap[n / 8] & (1 << (7 - n % 8))) {
      sprintf(line, "%d\n", n);
      fputs(line, out);
    }
  }
  free(bitmap);
  fclose(in);
  fclose(out);
}


x86 assembly (clang, -O0):
<sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe55(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe43(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    $0x1312d0,%edi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x54(%rbp)
mov    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x1312d0,%edx
call   1060 <memset@plt>
lea    -0x50(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x1f,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     1258 <sort+0xc8>
lea    -0x50(%rbp),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    $0x7,%ecx
sub    %edx,%ecx
mov    $0x1,%esi
shl    %cl,%esi
mov    -0x28(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x54(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x60(%rbp),%rax
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%edx
or     %esi,%edx
mov    %dl,(%rax,%rcx,1)
jmp    11ed <sort+0x5d>
movl   $0x0,-0x54(%rbp)
cmpl   $0x989680,-0x54(%rbp)
jge    12eb <sort+0x15b>
mov    -0x28(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x54(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x70(%rbp),%rax
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x64(%rbp)
mov    -0x54(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    -0x64(%rbp),%eax
mov    $0x7,%ecx
sub    %edx,%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     12d8 <sort+0x148>
lea    -0x50(%rbp),%rdi
mov    -0x54(%rbp),%edx
lea    0xd3e(%rip),%rsi
call   10b0 <sprintf@plt>
lea    -0x50(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <fputs@plt>
jmp    12dd <sort+0x14d>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    125f <sort+0xcf>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
lea    0xe58(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%r15
lea    0xe4b(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
mov    %rax,%r14
mov    $0x1312d0,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
xor    %ebp,%ebp
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x1312d0,%edx
call   1060 <memset@plt>
mov    %rsp,%rdi
mov    $0x1f,%esi
mov    %r15,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1240 <sort+0xb0>
mov    %rsp,%r12
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   10a0 <atoi@plt>
lea    0x7(%rax),%edx
test   %eax,%eax
cmovns %eax,%edx
mov    %edx,%ecx
and    $0xfffffff8,%ecx
sub    %ecx,%eax
mov    $0x7,%cl
sub    %al,%cl
mov    $0x1,%eax
shl    %cl,%eax
sar    $0x3,%edx
movslq %edx,%rcx
or     %al,(%rbx,%rcx,1)
mov    %r12,%rdi
mov    $0x1f,%esi
mov    %r15,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
jne    1200 <sort+0x70>
lea    0xdbd(%rip),%r12
mov    %rsp,%r13
jmp    125b <sort+0xcb>
nopl   0x0(%rax)
add    $0x1,%ebp
cmp    $0x989680,%ebp
je     128e <sort+0xfe>
mov    %ebp,%eax
shr    $0x3,%rax
movzbl (%rbx,%rax,1),%eax
mov    %ebp,%ecx
not    %cl
and    $0x7,%cl
movzbl %cl,%ecx
bt     %ecx,%eax
jae    1250 <sort+0xc0>
mov    %r13,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
call   10b0 <sprintf@plt>
mov    %r13,%rdi
mov    %r14,%rsi
call   1050 <fputs@plt>
jmp    1250 <sort+0xc0>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define void @sort(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca [32 x i8]
%9 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%10 = load i8*, i8** %3
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %5
%12 = load i8*, i8** %4
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %13, i32** %6
%14 = call i64 @malloc(i32 1250000)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %7
store i32 0, i32* %9
%16 = load i8*, i8** %7
%17 = call i32 @memset(i8* %16, i32 0, i32 1250000)
br label %18
18: ; preds = %23, %2
%19 = getelementptr inbounds [32 x i8], [32 x i8]* %8, i64 0, i64 0
%20 = load i32*, i32** %5
%21 = call i32* @fgets(i8* %19, i32 31, i32* %20)
%22 = icmp ne i32* %21, null
br i1 %22, label %23, label %39
23: ; preds = %18
%24 = getelementptr inbounds [32 x i8], [32 x i8]* %8, i64 0, i64 0
%25 = call i32 @atoi(i8* %24)
store i32 %25, i32* %9
%26 = load i32, i32* %9
%27 = srem i32 %26, 8
%28 = sub nsw i32 7, %27
%29 = shl i32 1, %28
%30 = load i8*, i8** %7
%31 = load i32, i32* %9
%32 = sdiv i32 %31, 8
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %30, i64 %33
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = or i32 %36, %29
%38 = trunc i32 %37 to i8
store i8 %38, i8* %34
br label %18
39: ; preds = %18
store i32 0, i32* %9
br label %40
40: ; preds = %65, %39
%41 = load i32, i32* %9
%42 = icmp slt i32 %41, 10000000
br i1 %42, label %43, label %68
43: ; preds = %40
%44 = load i8*, i8** %7
%45 = load i32, i32* %9
%46 = sdiv i32 %45, 8
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %44, i64 %47
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = load i32, i32* %9
%52 = srem i32 %51, 8
%53 = sub nsw i32 7, %52
%54 = shl i32 1, %53
%55 = and i32 %50, %54
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %64
57: ; preds = %43
%58 = getelementptr inbounds [32 x i8], [32 x i8]* %8, i64 0, i64 0
%59 = load i32, i32* %9
%60 = call i32 @sprintf(i8* %58, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %59)
%61 = getelementptr inbounds [32 x i8], [32 x i8]* %8, i64 0, i64 0
%62 = load i32*, i32** %6
%63 = call i32 @fputs(i8* %61, i32* %62)
br label %64
64: ; preds = %57, %43
br label %65
65: ; preds = %64
%66 = load i32, i32* %9
%67 = add nsw i32 %66, 1
store i32 %67, i32* %9
br label %40
68: ; preds = %40
%69 = load i8*, i8** %7
%70 = call i32 @free(i8* %69)
%71 = load i32*, i32** %5
%72 = call i32 @fclose(i32* %71)
%73 = load i32*, i32** %6
%74 = call i32 @fclose(i32* %73)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define void @sort(i8* nocapture %0, i8* nocapture %1) {
%3 = alloca [32 x i8]
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i64 @malloc(i32 1250000)
%7 = inttoptr i64 %6 to i8*
%8 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%9 = tail call i32 @memset(i8* %7, i32 0, i32 1250000)
%10 = call i32* @fgets(i8* %8, i32 31, i32* %4)
%11 = icmp eq i32* %10, null
br i1 %11, label %25, label %12
12: ; preds = %2, %12
%13 = call i32 @atoi(i8* %8)
%14 = srem i32 %13, 8
%15 = sub nsw i32 7, %14
%16 = shl nuw nsw i32 1, %15
%17 = sdiv i32 %13, 8
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %7, i64 %18
%20 = load i8, i8* %19
%21 = trunc i32 %16 to i8
%22 = or i8 %20, %21
store i8 %22, i8* %19
%23 = call i32* @fgets(i8* %8, i32 31, i32* %4)
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %12
25: ; preds = %12, %2
br label %26
26: ; preds = %25, %41
%27 = phi i32 [ %42, %41 ], [ 0, %25 ]
%28 = lshr i32 %27, 3
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %7, i64 %29
%31 = load i8, i8* %30
%32 = zext i8 %31 to i32
%33 = and i32 %27, 7
%34 = xor i32 %33, 7
%35 = shl nuw i32 1, %34
%36 = and i32 %35, %32
%37 = icmp eq i32 %36, 0
br i1 %37, label %41, label %38
38: ; preds = %26
%39 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %27)
%40 = call i32 @fputs(i8* %8, i32* %5)
br label %41
41: ; preds = %26, %38
%42 = add nuw nsw i32 %27, 1
%43 = icmp eq i32 %42, 10000000
br i1 %43, label %44, label %26
44: ; preds = %41
%45 = call i32 @free(i8* %7)
%46 = call i32 @fclose(i32* %4)
%47 = call i32 @fclose(i32* %5)
ret void
}