#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*/ fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int b[100][50];
  FILE *f;
  f = fopen("b.txt", "r");
  for (int i = 0; i < 100; i++) {
    for (int j = 0; j < 50; j++) {
      fscanf(f, "%1d", &b[i][j]);
    }
  }
  fclose(f);
  int carry = 0;
  int sum = 0;
  for (int j = 12 - 1; j >= 0; j--) {
    sum = 0;
    for (int i = 0; i < 100; i++) {
      sum += b[i][j];
    }
    sum += carry;
    carry = sum / 10;
    sum %= 10;
    printf("%d", sum);
  }
  printf("\n");
  printf("%d\n", carry);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4e50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xea7(%rip),%rdi
lea    0xea6(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x4e38(%rbp)
movl   $0x0,-0x4e3c(%rbp)
cmpl   $0x64,-0x4e3c(%rbp)
jge    1200 <main+0xc0>
movl   $0x0,-0x4e40(%rbp)
cmpl   $0x32,-0x4e40(%rbp)
jge    11e7 <main+0xa7>
mov    -0x4e38(%rbp),%rdi
movslq -0x4e3c(%rbp),%rax
lea    -0x4e30(%rbp),%rdx
imul   $0xc8,%rax,%rax
add    %rax,%rdx
movslq -0x4e40(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdx
lea    0xe3a(%rip),%rsi
call   1050 <fscanf@plt>
mov    -0x4e40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4e40(%rbp)
jmp    118d <main+0x4d>
jmp    11ec <main+0xac>
mov    -0x4e3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4e3c(%rbp)
jmp    1176 <main+0x36>
mov    -0x4e38(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4e44(%rbp)
movl   $0x0,-0x4e48(%rbp)
movl   $0xb,-0x4e4c(%rbp)
cmpl   $0x0,-0x4e4c(%rbp)
jl     12fc <main+0x1bc>
movl   $0x0,-0x4e48(%rbp)
movl   $0x0,-0x4e50(%rbp)
cmpl   $0x64,-0x4e50(%rbp)
jge    129a <main+0x15a>
movslq -0x4e50(%rbp),%rcx
lea    -0x4e30(%rbp),%rax
imul   $0xc8,%rcx,%rcx
add    %rcx,%rax
movslq -0x4e4c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
add    -0x4e48(%rbp),%eax
mov    %eax,-0x4e48(%rbp)
mov    -0x4e50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4e50(%rbp)
jmp    124b <main+0x10b>
mov    -0x4e44(%rbp),%eax
add    -0x4e48(%rbp),%eax
mov    %eax,-0x4e48(%rbp)
mov    -0x4e48(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4e44(%rbp)
mov    -0x4e48(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x4e48(%rbp)
mov    -0x4e48(%rbp),%esi
lea    0xd2b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4e4c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4e4c(%rbp)
jmp    122a <main+0xea>
lea    0xd0e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4e44(%rbp),%esi
lea    0xcf8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x4e50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x4e20,%rsp
lea    0xe99(%rip),%rdi
lea    0xe98(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r15
mov    %rsp,%r13
xor    %r12d,%r12d
lea    0xe85(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    (%rbx,%r13,1),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
call   1060 <fscanf@plt>
add    $0x4,%rbx
cmp    $0xc8,%rbx
jne    11a0 <main+0x50>
add    $0x1,%r12
add    $0xc8,%r13
cmp    $0x64,%r12
jne    1190 <main+0x40>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    $0xb,%r15d
mov    %rsp,%rbx
lea    0xe27(%rip),%r14
xor    %r12d,%r12d
nopl   0x0(%rax,%rax,1)
pxor   %xmm0,%xmm0
mov    $0x284,%eax
nopl   0x0(%rax)
movd   (%rbx,%rax,1),%xmm1
movd   -0xc8(%rbx,%rax,1),%xmm2
ff ff
punpckldq %xmm1,%xmm2
movd   -0x190(%rbx,%rax,1),%xmm1
ff ff
movd   -0x258(%rbx,%rax,1),%xmm3
ff ff
punpckldq %xmm1,%xmm3
punpcklqdq %xmm2,%xmm3
paddd  %xmm3,%xmm0
add    $0x320,%rax
cmp    $0x50a4,%rax
jne    1200 <main+0xb0>
pshufd $0xee,%xmm0,%xmm1
paddd  %xmm0,%xmm1
pshufd $0x55,%xmm1,%xmm0
paddd  %xmm1,%xmm0
movd   %xmm0,%eax
add    %r12d,%eax
movslq %eax,%rsi
imul   $0x66666667,%rsi,%r12
mov    %r12,%rax
shr    $0x3f,%rax
sar    $0x22,%r12
add    %eax,%r12d
lea    (%r12,%r12,1),%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0xfffffffffffffffc,%rbx
sub    $0x1,%r15
jae    11f0 <main+0xa0>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xd6e(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x4e20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [6 x i8] c"b.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c"%1d\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.5 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca [100 x [50 x i32]]
%2 = bitcast [100 x [50 x i32]]* %1 to i8*
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %4
4: ; preds = %0, %8
%5 = phi i64 [ 0, %0 ], [ %9, %8 ]
br label %11
6: ; preds = %8
%7 = call i32 @fclose(i32* %3)
br label %17
8: ; preds = %11
%9 = add nuw nsw i64 %5, 1
%10 = icmp eq i64 %9, 100
br i1 %10, label %6, label %4
11: ; preds = %4, %11
%12 = phi i64 [ 0, %4 ], [ %15, %11 ]
%13 = getelementptr inbounds [100 x [50 x i32]], [100 x [50 x i32]]* %1, i64 0, i64 %5, i64 %12
%14 = call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32* %13)
%15 = add nuw nsw i64 %12, 1
%16 = icmp eq i64 %15, 50
br i1 %16, label %8, label %11
17: ; preds = %41, %6
%18 = phi i64 [ 11, %6 ], [ %47, %41 ]
%19 = phi i32 [ 0, %6 ], [ %44, %41 ]
br label %20
20: ; preds = %20, %17
%21 = phi i64 [ 0, %17 ], [ %39, %20 ]
%22 = phi <4 x i32> [ zeroinitializer, %17 ], [ %38, %20 ]
%23 = or i64 %21, 1
%24 = or i64 %21, 2
%25 = or i64 %21, 3
%26 = getelementptr inbounds [100 x [50 x i32]], [100 x [50 x i32]]* %1, i64 0, i64 %21, i64 %18
%27 = getelementptr inbounds [100 x [50 x i32]], [100 x [50 x i32]]* %1, i64 0, i64 %23, i64 %18
%28 = getelementptr inbounds [100 x [50 x i32]], [100 x [50 x i32]]* %1, i64 0, i64 %24, i64 %18
%29 = getelementptr inbounds [100 x [50 x i32]], [100 x [50 x i32]]* %1, i64 0, i64 %25, i64 %18
%30 = load i32, i32* %26
%31 = load i32, i32* %27
%32 = load i32, i32* %28
%33 = load i32, i32* %29
%34 = insertelement <4 x i32> poison, i32 %30, i64 0
%35 = insertelement <4 x i32> %34, i32 %31, i64 1
%36 = insertelement <4 x i32> %35, i32 %32, i64 2
%37 = insertelement <4 x i32> %36, i32 %33, i64 3
%38 = add <4 x i32> %37, %22
%39 = add nuw i64 %21, 4
%40 = icmp eq i64 %39, 100
br i1 %40, label %41, label %20
41: ; preds = %20
%42 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %38)
%43 = add nsw i32 %42, %19
%44 = sdiv i32 %43, 10
%45 = srem i32 %43, 10
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %45)
%47 = add nsw i64 %18, -1
%48 = icmp eq i64 %18, 0
br i1 %48, label %49, label %17
49: ; preds = %41
%50 = call i32 @putchar(i32 10)
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %44)
ret i32 0
}