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

/* Variables and functions */
scalar_t__ EOF;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ stderr;
int main() {
  FILE *ifp;
  FILE *ofp;
  char infile_name[] = "unsorted_phonebook.txt";
  char outfile_name[] = "sorted_phonebook_c.txt";
  int bv_size = 312500;
  int *ph_num;
  int bit = 0;
  int idx = 0;
  uint32_t comp_int = 0;
  uint32_t *bvp = (uint32_t *)malloc(bv_size * sizeof(uint32_t));
  for (idx = 0; idx < bv_size; idx++) {
    bvp[idx] = 0;
  }
  ifp = fopen(infile_name, "r");
  if (ifp == NULL) {
    fprintf(stderr, "Can't open input file in.list!\n");
    exit(1);
  }
  ofp = fopen(outfile_name, "w");
  if (ofp == NULL) {
    fprintf(stderr, "Can't open output file %s!\n", outfile_name);
    exit(1);
  }
  while (fscanf(ifp, "%d", ph_num) != EOF) {
    idx = *ph_num / 32;
    bit = *ph_num % 32;
    comp_int = 1;
    comp_int <<= bit;
    *(bvp + idx) = (*(bvp + idx) | comp_int);
  }
  for (idx = 0; idx < bv_size; idx++) {
    comp_int = 1;
    if (*(bvp + idx) > 0) {
      for (bit = 0; bit < 32; bit++) {
        if (comp_int & *(bvp + idx))
          fprintf(ofp, "%d\n", idx * 32 + bit);
        comp_int <<= 1;
      }
    }
  }
  fclose(ifp);
  fclose(ofp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe87(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe84(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xe82(%rip),%eax
mov    %eax,-0x20(%rbp)
mov    0xe7c(%rip),%ax
mov    %ax,-0x1c(%rbp)
mov    0xe74(%rip),%al
mov    %al,-0x1a(%rbp)
mov    0xe74(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0xe71(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    0xe6f(%rip),%eax
mov    %eax,-0x40(%rbp)
mov    0xe69(%rip),%ax
mov    %ax,-0x3c(%rbp)
mov    0xe61(%rip),%al
mov    %al,-0x3a(%rbp)
movl   $0x4c4b4,-0x54(%rbp)
movl   $0x0,-0x64(%rbp)
movl   $0x0,-0x68(%rbp)
movl   $0x0,-0x6c(%rbp)
movslq -0x54(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x78(%rbp)
movl   $0x0,-0x68(%rbp)
mov    -0x68(%rbp),%eax
cmp    -0x54(%rbp),%eax
jge    1237 <main+0xd7>
mov    -0x78(%rbp),%rax
movslq -0x68(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
jmp    120e <main+0xae>
lea    -0x30(%rbp),%rdi
lea    0xdf5(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1278 <main+0x118>
mov    0x2d7b(%rip),%rax
movslq (%rax),%rdi
lea    0xdd2(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    -0x50(%rbp),%rdi
lea    0xdd6(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12bd <main+0x15d>
mov    0x2d3a(%rip),%rax
movslq (%rax),%rdi
lea    -0x50(%rbp),%rdx
lea    0xdaf(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    12c2 <main+0x162>
mov    -0x10(%rbp),%rdi
mov    -0x60(%rbp),%rdx
lea    0xda6(%rip),%rsi
call   1040 <fscanf@plt>
mov    0x2d0b(%rip),%rcx
cmp    (%rcx),%rax
je     1338 <main+0x1d8>
mov    -0x60(%rbp),%rax
mov    (%rax),%eax
mov    $0x20,%ecx
cltd
idiv   %ecx
mov    %eax,-0x68(%rbp)
mov    -0x60(%rbp),%rax
mov    (%rax),%eax
mov    $0x20,%ecx
cltd
idiv   %ecx
mov    %edx,-0x64(%rbp)
movl   $0x1,-0x6c(%rbp)
mov    -0x64(%rbp),%ecx
mov    -0x6c(%rbp),%eax
shl    %cl,%eax
mov    %eax,-0x6c(%rbp)
mov    -0x78(%rbp),%rax
movslq -0x68(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
or     -0x6c(%rbp),%edx
mov    -0x78(%rbp),%rax
movslq -0x68(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
jmp    12c2 <main+0x162>
movl   $0x0,-0x68(%rbp)
mov    -0x68(%rbp),%eax
cmp    -0x54(%rbp),%eax
jge    13d6 <main+0x276>
movl   $0x1,-0x6c(%rbp)
mov    -0x78(%rbp),%rax
movslq -0x68(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jle    13c3 <main+0x263>
movl   $0x0,-0x64(%rbp)
cmpl   $0x20,-0x64(%rbp)
jge    13be <main+0x25e>
mov    -0x6c(%rbp),%eax
mov    -0x78(%rbp),%rcx
movslq -0x68(%rbp),%rdx
and    (%rcx,%rdx,4),%eax
cmp    $0x0,%eax
je     13a7 <main+0x247>
mov    -0x18(%rbp),%rdi
mov    -0x68(%rbp),%edx
shl    $0x5,%edx
add    -0x64(%rbp),%edx
lea    0xcda(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x6c(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x6c(%rbp)
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    136b <main+0x20b>
jmp    13c3 <main+0x263>
jmp    13c8 <main+0x268>
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
jmp    133f <main+0x1df>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
movaps 0xe6b(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movabs $0x7478742e6b6f6f,%rax
mov    %rax,0x3f(%rsp)
movaps 0xe70(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movabs $0x7478742e635f6b,%rax
mov    %rax,0x1f(%rsp)
mov    $0x1312d0,%edi
call   1070 <malloc@plt>
mov    %rax,%r13
mov    $0x1312d0,%edx
mov    %rax,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
lea    0xe50(%rip),%rsi
lea    0x30(%rsp),%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     12e1 <main+0x161>
mov    %rax,%rbp
lea    0xe55(%rip),%rsi
lea    0x10(%rsp),%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     130b <main+0x18b>
mov    %rax,%r15
lea    0xe56(%rip),%rsi
mov    %rbp,%rdi
call   1050 <fscanf@plt>
mov    0x2db8(%rip),%rbx
cmp    (%rbx),%rax
je     1255 <main+0xd5>
lea    0xe3b(%rip),%r12
nopl   0x0(%rax)
orb    $0x1,0x0(%r13)
mov    %rbp,%rdi
mov    %r12,%rsi
call   1050 <fscanf@plt>
cmp    (%rbx),%rax
jne    1240 <main+0xc0>
mov    %rbp,0x8(%rsp)
xor    %ebx,%ebx
xor    %ebp,%ebp
jmp    1270 <main+0xf0>
add    $0x1,%rbp
add    $0x20,%ebx
cmp    $0x4c4b4,%rbp
je     12be <main+0x13e>
mov    0x0(%r13,%rbp,4),%eax
test   %eax,%eax
jle    1260 <main+0xe0>
xor    %r14d,%r14d
mov    $0x1,%r12d
test   %r12d,%eax
je     12a5 <main+0x125>
nopw   0x0(%rax,%rax,1)
lea    (%rbx,%r14,1),%edx
mov    %r15,%rdi
lea    0xddc(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
cmp    $0x1f,%r14d
je     1260 <main+0xe0>
add    %r12d,%r12d
mov    0x0(%r13,%rbp,4),%eax
add    $0x1,%r14d
test   %r12d,%eax
jne    1290 <main+0x110>
jmp    12a5 <main+0x125>
mov    0x8(%rsp),%rdi
call   1030 <fclose@plt>
mov    %r15,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cf0(%rip),%rax
movslq (%rax),%rcx
lea    0xd47(%rip),%rdi
mov    $0x1f,%esi
mov    $0x1,%edx
call   10a0 <fwrite@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2cc6(%rip),%rax
movslq (%rax),%rdi
lea    0xd3f(%rip),%rsi
lea    0x10(%rsp),%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@__const.main.infile_name = [23 x i8] c"unsorted_phonebook.txt\00"
@__const.main.outfile_name = [23 x i8] c"sorted_phonebook_c.txt\00"
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [32 x i8] c"Can't open input file in.list!\0A\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [28 x i8] c"Can't open output file %s!\0A\00"
@.str.4 = [3 x i8] c"%d\00"
@EOF = global i64 0
@.str.5 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca [23 x i8]
%5 = alloca [23 x i8]
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
store i32 0, i32* %1
%12 = bitcast [23 x i8]* %4 to i8*
%13 = bitcast [23 x i8]* %5 to i8*
store i32 312500, i32* %6
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
%14 = load i32, i32* %6
%15 = sext i32 %14 to i64
%16 = mul i64 %15, 4
%17 = trunc i64 %16 to i32
%18 = call i64 @malloc(i32 %17)
%19 = inttoptr i64 %18 to i32*
store i32* %19, i32** %11
store i32 0, i32* %9
br label %20
20: ; preds = %29, %0
%21 = load i32, i32* %9
%22 = load i32, i32* %6
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %32
24: ; preds = %20
%25 = load i32*, i32** %11
%26 = load i32, i32* %9
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %25, i64 %27
store i32 0, i32* %28
br label %29
29: ; preds = %24
%30 = load i32, i32* %9
%31 = add nsw i32 %30, 1
store i32 %31, i32* %9
br label %20
32: ; preds = %20
%33 = getelementptr inbounds [23 x i8], [23 x i8]* %4, i64 0, i64 0
%34 = call i32* @fopen(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %34, i32** %2
%35 = load i32*, i32** %2
%36 = icmp eq i32* %35, null
br i1 %36, label %37, label %43
37: ; preds = %32
%38 = load i32, i32* @stderr
%39 = sext i32 %38 to i64
%40 = inttoptr i64 %39 to i32*
%41 = call i32 (i32*, i8*, ...) @fprintf(i32* %40, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %32
%44 = getelementptr inbounds [23 x i8], [23 x i8]* %5, i64 0, i64 0
%45 = call i32* @fopen(i8* %44, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %45, i32** %3
%46 = load i32*, i32** %3
%47 = icmp eq i32* %46, null
br i1 %47, label %48, label %55
48: ; preds = %43
%49 = load i32, i32* @stderr
%50 = sext i32 %49 to i64
%51 = inttoptr i64 %50 to i32*
%52 = getelementptr inbounds [23 x i8], [23 x i8]* %5, i64 0, i64 0
%53 = call i32 (i32*, i8*, ...) @fprintf(i32* %51, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %52)
%54 = call i32 @exit(i32 1)
unreachable
55: ; preds = %43
br label %56
56: ; preds = %62, %55
%57 = load i32*, i32** %2
%58 = load i32*, i32** %7
%59 = call i64 @fscanf(i32* %57, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %58)
%60 = load i64, i64* @EOF
%61 = icmp ne i64 %59, %60
br i1 %61, label %62, label %83
62: ; preds = %56
%63 = load i32*, i32** %7
%64 = load i32, i32* %63
%65 = sdiv i32 %64, 32
store i32 %65, i32* %9
%66 = load i32*, i32** %7
%67 = load i32, i32* %66
%68 = srem i32 %67, 32
store i32 %68, i32* %8
store i32 1, i32* %10
%69 = load i32, i32* %8
%70 = load i32, i32* %10
%71 = shl i32 %70, %69
store i32 %71, i32* %10
%72 = load i32*, i32** %11
%73 = load i32, i32* %9
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i32, i32* %72, i64 %74
%76 = load i32, i32* %75
%77 = load i32, i32* %10
%78 = or i32 %76, %77
%79 = load i32*, i32** %11
%80 = load i32, i32* %9
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds i32, i32* %79, i64 %81
store i32 %78, i32* %82
br label %56
83: ; preds = %56
store i32 0, i32* %9
br label %84
84: ; preds = %123, %83
%85 = load i32, i32* %9
%86 = load i32, i32* %6
%87 = icmp slt i32 %85, %86
br i1 %87, label %88, label %126
88: ; preds = %84
store i32 1, i32* %10
%89 = load i32*, i32** %11
%90 = load i32, i32* %9
%91 = sext i32 %90 to i64
%92 = getelementptr inbounds i32, i32* %89, i64 %91
%93 = load i32, i32* %92
%94 = icmp sgt i32 %93, 0
br i1 %94, label %95, label %122
95: ; preds = %88
store i32 0, i32* %8
br label %96
96: ; preds = %118, %95
%97 = load i32, i32* %8
%98 = icmp slt i32 %97, 32
br i1 %98, label %99, label %121
99: ; preds = %96
%100 = load i32, i32* %10
%101 = load i32*, i32** %11
%102 = load i32, i32* %9
%103 = sext i32 %102 to i64
%104 = getelementptr inbounds i32, i32* %101, i64 %103
%105 = load i32, i32* %104
%106 = and i32 %100, %105
%107 = icmp ne i32 %106, 0
br i1 %107, label %108, label %115
108: ; preds = %99
%109 = load i32*, i32** %3
%110 = load i32, i32* %9
%111 = mul nsw i32 %110, 32
%112 = load i32, i32* %8
%113 = add nsw i32 %111, %112
%114 = call i32 (i32*, i8*, ...) @fprintf(i32* %109, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %113)
br label %115
115: ; preds = %108, %99
%116 = load i32, i32* %10
%117 = shl i32 %116, 1
store i32 %117, i32* %10
br label %118
118: ; preds = %115
%119 = load i32, i32* %8
%120 = add nsw i32 %119, 1
store i32 %120, i32* %8
br label %96
121: ; preds = %96
br label %122
122: ; preds = %121, %88
br label %123
123: ; preds = %122
%124 = load i32, i32* %9
%125 = add nsw i32 %124, 1
store i32 %125, i32* %9
br label %84
126: ; preds = %84
%127 = load i32*, i32** %2
%128 = call i32 @fclose(i32* %127)
%129 = load i32*, i32** %3
%130 = call i32 @fclose(i32* %129)
ret i32 0
}

LLVM IR (-O2):
@__const.main.infile_name = [23 x i8] c"unsorted_phonebook.txt\00"
@__const.main.outfile_name = [23 x i8] c"sorted_phonebook_c.txt\00"
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [32 x i8] c"Can't open input file in.list!\0A\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [28 x i8] c"Can't open output file %s!\0A\00"
@.str.4 = [3 x i8] c"%d\00"
@EOF = global i64 0
@.str.5 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca [23 x i8]
%2 = alloca [23 x i8]
%3 = getelementptr inbounds [23 x i8], [23 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [23 x i8], [23 x i8]* %2, i64 0, i64 0
%5 = tail call i64 @malloc(i32 1250000)
%6 = inttoptr i64 %5 to i32*
%7 = inttoptr i64 %5 to i8*
%8 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %16
10: ; preds = %0
%11 = load i32, i32* @stderr
%12 = sext i32 %11 to i64
%13 = inttoptr i64 %12 to i32*
%14 = tail call i64 @fwrite(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i64 31, i64 1, i32* %13)
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %0
%17 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %23, label %19
19: ; preds = %16
%20 = tail call i64 @fscanf(i32* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* undef)
%21 = load i64, i64* @EOF
%22 = icmp eq i64 %20, %21
br i1 %22, label %35, label %29
23: ; preds = %16
%24 = load i32, i32* @stderr
%25 = sext i32 %24 to i64
%26 = inttoptr i64 %25 to i32*
%27 = call i32 (i32*, i8*, ...) @fprintf(i32* %26, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %19, %29
%30 = load i32, i32* %6
%31 = or i32 %30, 1
store i32 %31, i32* %6
%32 = tail call i64 @fscanf(i32* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* undef)
%33 = load i64, i64* @EOF
%34 = icmp eq i64 %32, %33
br i1 %34, label %35, label %29
35: ; preds = %29, %19
br label %36
36: ; preds = %35, %59
%37 = phi i64 [ %60, %59 ], [ 0, %35 ]
%38 = getelementptr inbounds i32, i32* %6, i64 %37
%39 = load i32, i32* %38
%40 = icmp sgt i32 %39, 0
br i1 %40, label %41, label %59
41: ; preds = %36
%42 = trunc i64 %37 to i32
%43 = shl i32 %42, 5
br label %44
44: ; preds = %56, %41
%45 = phi i32 [ %39, %41 ], [ %58, %56 ]
%46 = phi i32 [ 1, %41 ], [ %57, %56 ]
%47 = phi i32 [ 0, %41 ], [ %54, %56 ]
%48 = and i32 %45, %46
%49 = icmp eq i32 %48, 0
br i1 %49, label %53, label %50
50: ; preds = %44
%51 = add nuw nsw i32 %47, %43
%52 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %51)
br label %53
53: ; preds = %50, %44
%54 = add nuw nsw i32 %47, 1
%55 = icmp eq i32 %54, 32
br i1 %55, label %59, label %56
56: ; preds = %53
%57 = shl i32 %46, 1
%58 = load i32, i32* %38
br label %44
59: ; preds = %53, %36
%60 = add nuw nsw i64 %37, 1
%61 = icmp eq i64 %60, 312500
br i1 %61, label %62, label %36
62: ; preds = %59
%63 = tail call i32 @fclose(i32* %8)
%64 = tail call i32 @fclose(i32* %17)
ret i32 0
}