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

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fprintf(int /*<<< orphan*/ *, char *, unsigned int);
int /*<<< orphan*/ puts(char *);
int main() {
  unsigned int bit_array = 0;
  unsigned int a = 1;
  unsigned int result;
  FILE *fr;
  FILE *fw;
  char row[10];
  fr = fopen("out/testdata", "r");
  if (!fr) {
    puts("read error");
    exit(1);
  }
  while (fgets(row, sizeof(row), fr) != NULL) {
    int x = atoi(row);
    bit_array = bit_array | (a << x);
  }
  fclose(fr);
  fw = fopen("out/output_bit_array_sort", "w");
  unsigned i;
  for (i = 0; i < 1000000; i++) {
    if (fprintf(fw, "%07u\n", bit_array & i) < 0) {
      puts("write error");
      exit(1);
    }
  }
  fclose(fw);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
lea    0xe6c(%rip),%rdi
lea    0xe7b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c5 <main+0x55>
lea    0xe57(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    11ca <main+0x5a>
lea    -0x2a(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0xa,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1209 <main+0x99>
lea    -0x2a(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%eax
mov    -0xc(%rbp),%edx
mov    -0x30(%rbp),%ecx
shl    %cl,%edx
mov    %edx,%ecx
or     %ecx,%eax
mov    %eax,-0x8(%rbp)
jmp    11ca <main+0x5a>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xdff(%rip),%rdi
lea    0xe12(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x34(%rbp)
cmpl   $0xf4240,-0x34(%rbp)
jae    1286 <main+0x116>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%edx
and    -0x34(%rbp),%edx
lea    0xde6(%rip),%rsi
call   1060 <fprintf@plt>
cmp    $0x0,%rax
jge    1273 <main+0x103>
lea    0xdd6(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    1278 <main+0x108>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1230 <main+0xc0>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xe7f(%rip),%rdi
lea    0xe8e(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     125a <main+0xea>
mov    %rax,%r14
lea    0xe(%rsp),%rdi
mov    $0xa,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
xor    %ebp,%ebp
mov    $0x0,%ebx
test   %rax,%rax
je     11e0 <main+0x70>
xor    %ebx,%ebx
lea    0xe(%rsp),%r15
xchg   %ax,%ax
mov    %r15,%rdi
call   1080 <atoi@plt>
bts    %eax,%ebx
mov    %r15,%rdi
mov    $0xa,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    11c0 <main+0x50>
mov    %r14,%rdi
call   1040 <fclose@plt>
lea    0xe29(%rip),%rdi
lea    0xe3c(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r15
lea    0xe2f(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebp,%edx
and    %ebx,%edx
mov    %r15,%rdi
mov    %r14,%rsi
call   1060 <fprintf@plt>
test   %rax,%rax
js     1244 <main+0xd4>
add    $0x1,%ebp
cmp    $0xf4240,%ebp
jne    1210 <main+0xa0>
mov    %r15,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdef(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xdac(%rip),%rdi
jmp    124b <main+0xdb>

LLVM IR (-O0):
@.str = [13 x i8] c"out/testdata\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [11 x i8] c"read error\00"
@.str.3 = [26 x i8] c"out/output_bit_array_sort\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [6 x i8] c"%07u\0A\00"
@.str.6 = [12 x i8] c"write error\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca [10 x i8]
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
store i32 1, i32* %3
%10 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %5
%11 = load i32*, i32** %5
%12 = icmp ne i32* %11, null
br i1 %12, label %16, label %13
13: ; preds = %0
%14 = call i32 @puts(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %0
br label %17
17: ; preds = %22, %16
%18 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%19 = load i32*, i32** %5
%20 = call i32* @fgets(i8* %18, i32 10, i32* %19)
%21 = icmp ne i32* %20, null
br i1 %21, label %22, label %30
22: ; preds = %17
%23 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%24 = call i32 @atoi(i8* %23)
store i32 %24, i32* %8
%25 = load i32, i32* %2
%26 = load i32, i32* %3
%27 = load i32, i32* %8
%28 = shl i32 %26, %27
%29 = or i32 %25, %28
store i32 %29, i32* %2
br label %17
30: ; preds = %17
%31 = load i32*, i32** %5
%32 = call i32 @fclose(i32* %31)
%33 = call i32* @fopen(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %33, i32** %6
store i32 0, i32* %9
br label %34
34: ; preds = %48, %30
%35 = load i32, i32* %9
%36 = icmp ult i32 %35, 1000000
br i1 %36, label %37, label %51
37: ; preds = %34
%38 = load i32*, i32** %6
%39 = load i32, i32* %2
%40 = load i32, i32* %9
%41 = and i32 %39, %40
%42 = call i64 @fprintf(i32* %38, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %41)
%43 = icmp slt i64 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %37
%45 = call i32 @puts(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
%46 = call i32 @exit(i32 1)
unreachable
47: ; preds = %37
br label %48
48: ; preds = %47
%49 = load i32, i32* %9
%50 = add i32 %49, 1
store i32 %50, i32* %9
br label %34
51: ; preds = %34
%52 = load i32*, i32** %6
%53 = call i32 @fclose(i32* %52)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"out/testdata\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [11 x i8] c"read error\00"
@.str.3 = [26 x i8] c"out/output_bit_array_sort\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [6 x i8] c"%07u\0A\00"
@.str.6 = [12 x i8] c"write error\00"
define i32 @main() {
%1 = alloca [10 x i8]
%2 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %8, label %5
5: ; preds = %0
%6 = call i32* @fgets(i8* %2, i32 10, i32* %3)
%7 = icmp eq i32* %6, null
br i1 %7, label %18, label %11
8: ; preds = %0
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %5, %11
%12 = phi i32 [ %15, %11 ], [ 0, %5 ]
%13 = call i32 @atoi(i8* %2)
%14 = shl nuw i32 1, %13
%15 = or i32 %14, %12
%16 = call i32* @fgets(i8* %2, i32 10, i32* %3)
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %11
18: ; preds = %11, %5
%19 = phi i32 [ 0, %5 ], [ %15, %11 ]
%20 = call i32 @fclose(i32* %3)
%21 = call i32* @fopen(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %25
22: ; preds = %25
%23 = add nuw nsw i32 %26, 1
%24 = icmp eq i32 %23, 1000000
br i1 %24, label %33, label %25
25: ; preds = %18, %22
%26 = phi i32 [ 0, %18 ], [ %23, %22 ]
%27 = and i32 %26, %19
%28 = call i64 @fprintf(i32* %21, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %27)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %22
30: ; preds = %25
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %22
%34 = call i32 @fclose(i32* %21)
ret i32 0
}