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

/* Variables and functions */
int atoi(char *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int strlen(char *);
void transformInfile(FILE *fin, FILE *fout) {
  int num = 0;
  int total = 0;
  char data[2048];
  while (fgets(data, sizeof(data), fin)) {
    char newdata[2048];
    char numdata[2048];
    int numlength = 0;
    int i = 0;
    int j = 0;
    int k = 0;
    num = atoi(data);
    total += num;
    fprintf(fout, "num: %d\n", num);
    while (num != 0) {
      numdata[j] = num % 10;
      num = num / 10;
      j++;
    }
    numdata[j] = '\0';
    numlength = strlen(numdata);
    for (k = numlength; data[k] != '\0'; k++) {
      newdata[i] = data[k];
      i++;
    }
    newdata[i] = '\0';
    fprintf(fout, "%s", newdata);
  }
  fprintf(fout, "%d\n", total);
}


x86 assembly (clang, -O0):
<transformInfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1830,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
lea    -0x820(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x800,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     12cd <transformInfile+0x18d>
movl   $0x0,-0x1824(%rbp)
movl   $0x0,-0x1828(%rbp)
movl   $0x0,-0x182c(%rbp)
movl   $0x0,-0x1830(%rbp)
lea    -0x820(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe32(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
cmpl   $0x0,-0x14(%rbp)
je     121c <transformInfile+0xdc>
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %dl,%cl
movslq -0x182c(%rbp),%rax
mov    %cl,-0x1820(%rbp,%rax,1)
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0x182c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x182c(%rbp)
jmp    11d5 <transformInfile+0x95>
movslq -0x182c(%rbp),%rax
movb   $0x0,-0x1820(%rbp,%rax,1)
lea    -0x1820(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1824(%rbp)
mov    -0x1824(%rbp),%eax
mov    %eax,-0x1830(%rbp)
movslq -0x1830(%rbp),%rax
movsbl -0x820(%rbp,%rax,1),%eax
ff
cmp    $0x0,%eax
je     12a0 <transformInfile+0x160>
movslq -0x1830(%rbp),%rax
mov    -0x820(%rbp,%rax,1),%cl
movslq -0x1828(%rbp),%rax
mov    %cl,-0x1020(%rbp,%rax,1)
mov    -0x1828(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1828(%rbp)
mov    -0x1830(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1830(%rbp)
jmp    1249 <transformInfile+0x109>
movslq -0x1828(%rbp),%rax
movb   $0x0,-0x1020(%rbp,%rax,1)
mov    -0x10(%rbp),%rdi
lea    -0x1020(%rbp),%rdx
lea    0xd48(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1161 <transformInfile+0x21>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%edx
lea    0xd2a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
add    $0x1830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<transformInfile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1808,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsp,%rdi
mov    $0x800,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1278 <transformInfile+0x128>
mov    %rsp,%r15
lea    0x1000(%rsp),%r12
xor    %ebp,%ebp
jmp    11c3 <transformInfile+0x73>
nop
xor    %ecx,%ecx
add    %r13d,%ebp
mov    %ecx,%eax
movb   $0x0,0x1000(%rsp,%rax,1)
mov    %r12,%rdi
mov    %rbx,%rsi
call   1040 <fputs@plt>
mov    %r15,%rdi
mov    $0x800,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     127a <transformInfile+0x12a>
mov    %r15,%rdi
call   1070 <atoi@plt>
mov    %eax,%r13d
mov    %rbx,%rdi
lea    0xe28(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
xor    %eax,%eax
test   %r13d,%r13d
je     1225 <transformInfile+0xd5>
mov    %r13d,%ecx
nopl   0x0(%rax,%rax,1)
movslq %ecx,%rdx
imul   $0x66666667,%rdx,%rcx
mov    %rcx,%rsi
shr    $0x3f,%rsi
sar    $0x22,%rcx
add    %esi,%ecx
lea    (%rcx,%rcx,1),%esi
lea    (%rsi,%rsi,4),%esi
mov    %edx,%edi
sub    %esi,%edi
mov    %dil,0x800(%rsp,%rax,1)
add    $0x1,%rax
add    $0x9,%edx
cmp    $0x12,%edx
ja     11f0 <transformInfile+0xa0>
mov    %eax,%eax
movb   $0x0,0x800(%rsp,%rax,1)
lea    0x800(%rsp),%rdi
call   1030 <strlen@plt>
cltq
mov    (%rsp,%rax,1),%dl
test   %dl,%dl
je     1190 <transformInfile+0x40>
lea    0x1(%rsp),%rcx
add    %rcx,%rax
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %dl,0x1000(%rsp,%rcx,1)
movzbl (%rax,%rcx,1),%edx
add    $0x1,%rcx
test   %dl,%dl
jne    1260 <transformInfile+0x110>
jmp    1192 <transformInfile+0x42>
xor    %ebp,%ebp
lea    0xd84(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
add    $0x1808,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [9 x i8] c"num: %d\0A\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define void @transformInfile(i32* nocapture %0, i32* nocapture %1) {
%3 = alloca [2048 x i8]
%4 = alloca [2048 x i8]
%5 = alloca [2048 x i8]
%6 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%7 = call i64 @fgets(i8* %6, i32 2048, i32* %0)
%8 = icmp eq i64 %7, 0
br i1 %8, label %54, label %9
9: ; preds = %2
%10 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
%11 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
br label %12
12: ; preds = %9, %47
%13 = phi i32 [ 0, %9 ], [ %15, %47 ]
%14 = call i32 @atoi(i8* %6)
%15 = add nsw i32 %14, %13
%16 = call i32 (i32*, i8*, ...) @fprintf(i32* %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %14)
%17 = icmp eq i32 %14, 0
br i1 %17, label %28, label %18
18: ; preds = %12, %18
%19 = phi i64 [ %25, %18 ], [ 0, %12 ]
%20 = phi i32 [ %24, %18 ], [ %14, %12 ]
%21 = srem i32 %20, 10
%22 = trunc i32 %21 to i8
%23 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 %19
store i8 %22, i8* %23
%24 = sdiv i32 %20, 10
%25 = add nuw i64 %19, 1
%26 = add i32 %20, 9
%27 = icmp ult i32 %26, 19
br i1 %27, label %28, label %18
28: ; preds = %18, %12
%29 = phi i64 [ 0, %12 ], [ %25, %18 ]
%30 = and i64 %29, 4294967295
%31 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 %30
store i8 0, i8* %31
%32 = call i32 @strlen(i8* %11)
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 %33
%35 = load i8, i8* %34
%36 = icmp eq i8 %35, 0
br i1 %36, label %47, label %37
37: ; preds = %28, %37
%38 = phi i64 [ %42, %37 ], [ 0, %28 ]
%39 = phi i64 [ %43, %37 ], [ %33, %28 ]
%40 = phi i8 [ %45, %37 ], [ %35, %28 ]
%41 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 %38
store i8 %40, i8* %41
%42 = add nuw i64 %38, 1
%43 = add i64 %39, 1
%44 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 %43
%45 = load i8, i8* %44
%46 = icmp eq i8 %45, 0
br i1 %46, label %47, label %37
47: ; preds = %37, %28
%48 = phi i64 [ 0, %28 ], [ %42, %37 ]
%49 = and i64 %48, 4294967295
%50 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 %49
store i8 0, i8* %50
%51 = call i32 @fputs(i8* %10, i32* %1)
%52 = call i64 @fgets(i8* %6, i32 2048, i32* %0)
%53 = icmp eq i64 %52, 0
br i1 %53, label %54, label %12
54: ; preds = %47, %2
%55 = phi i32 [ 0, %2 ], [ %15, %47 ]
%56 = call i32 (i32*, i8*, ...) @fprintf(i32* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %55)
ret void
}