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

/* Variables and functions */
int BUFSIZ;
int /*<<< orphan*/ clear_buf(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int append_numbers(char input_file[], char output_file[]) {
  char buf[BUFSIZ];
  FILE *fp_in;
  FILE *fp_out;
  int i = 0;
  int index = 0;
  clear_buf(buf);
  fp_in = fopen(input_file, "r");
  fp_out = fopen(output_file, "w+");
  while (fgets(buf, sizeof(buf), fp_in)) {
    while (buf[index] != '\n' && index < BUFSIZ)
      index++;
    for (i = 0; i < 10; i++) {
      buf[index] = i + 48;
      buf[index + 1] = '\n';
      buf[index + 2] = 0;
      fprintf(fp_out, "%s", buf);
    }
    index = 0;
    clear_buf(buf);
  }
  fclose(fp_in);
  fclose(fp_out);
  return 0;
}


x86 assembly (clang, -O0):
<append_numbers>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e79(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x48(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x40(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
call   1070 <clear_buf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe52(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe40(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rax
mov    %eax,%esi
mov    -0x28(%rbp),%rdx
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     12a6 <append_numbers+0x156>
jmp    11ed <append_numbers+0x9d>
mov    -0x40(%rbp),%rax
movslq -0x38(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x49(%rbp)
je     1219 <append_numbers+0xc9>
mov    -0x38(%rbp),%eax
mov    0x2dcf(%rip),%rcx
cmp    (%rcx),%eax
setl   %al
mov    %al,-0x49(%rbp)
mov    -0x49(%rbp),%al
test   $0x1,%al
jne    1229 <append_numbers+0xd9>
jmp    1237 <append_numbers+0xe7>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    11ed <append_numbers+0x9d>
movl   $0x0,-0x34(%rbp)
cmpl   $0xa,-0x34(%rbp)
jge    1291 <append_numbers+0x141>
mov    -0x40(%rbp),%rdx
mov    -0x34(%rbp),%eax
add    $0x30,%eax
mov    %al,%cl
movslq -0x38(%rbp),%rax
mov    %cl,(%rdx,%rax,1)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
cltq
movb   $0xa,(%rdx,%rax,1)
mov    -0x38(%rbp),%eax
add    $0x2,%eax
cltq
movb   $0x0,(%rdx,%rax,1)
mov    -0x30(%rbp),%rdi
lea    0xd87(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    123e <append_numbers+0xee>
mov    -0x40(%rbp),%rdi
movl   $0x0,-0x38(%rbp)
call   1070 <clear_buf@plt>
jmp    11cb <append_numbers+0x7b>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<append_numbers>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %rdi,%r15
mov    0x2e75(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%rbx
mov    %r14,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
call   1070 <clear_buf@plt>
lea    0xe6f(%rip),%rsi
mov    %r15,%rdi
call   1060 <fopen@plt>
mov    %rax,%r15
lea    0xe5f(%rip),%rsi
mov    %r12,%rdi
call   1060 <fopen@plt>
mov    %rax,%r12
jmp    12c2 <append_numbers+0x172>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movw   $0xa30,-0x1(%rbx,%r13,1)
0a
movb   $0x0,0x1(%rbx,%r13,1)
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <fputs@plt>
movw   $0xa31,-0x1(%rbx,%r13,1)
0a
movb   $0x0,0x1(%rbx,%r13,1)
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <fputs@plt>
movw   $0xa32,-0x1(%rbx,%r13,1)
0a
movb   $0x0,0x1(%rbx,%r13,1)
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <fputs@plt>
movw   $0xa33,-0x1(%rbx,%r13,1)
0a
movb   $0x0,0x1(%rbx,%r13,1)
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <fputs@plt>
movw   $0xa34,-0x1(%rbx,%r13,1)
0a
movb   $0x0,0x1(%rbx,%r13,1)
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <fputs@plt>
movw   $0xa35,-0x1(%rbx,%r13,1)
0a
movb   $0x0,0x1(%rbx,%r13,1)
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <fputs@plt>
movw   $0xa36,-0x1(%rbx,%r13,1)
0a
movb   $0x0,0x1(%rbx,%r13,1)
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <fputs@plt>
movw   $0xa37,-0x1(%rbx,%r13,1)
0a
movb   $0x0,0x1(%rbx,%r13,1)
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <fputs@plt>
movw   $0xa38,-0x1(%rbx,%r13,1)
0a
movb   $0x0,0x1(%rbx,%r13,1)
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <fputs@plt>
movw   $0xa39,-0x1(%rbx,%r13,1)
0a
movb   $0x0,0x1(%rbx,%r13,1)
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <fputs@plt>
mov    %rbx,%rdi
call   1070 <clear_buf@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     130b <append_numbers+0x1bb>
mov    0x2d04(%rip),%rax
movslq (%rax),%rax
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0x1(%rcx),%r13
cmpb   $0xa,(%rbx,%rcx,1)
je     11c0 <append_numbers+0x70>
cmp    %rax,%rcx
mov    %r13,%rcx
jl     12f0 <append_numbers+0x1a0>
jmp    11c0 <append_numbers+0x70>
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    %r12,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @append_numbers(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%11 = load i32, i32* @BUFSIZ
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %5
%14 = alloca i8, i64 %12
store i64 %12, i64* %6
store i32 0, i32* %9
store i32 0, i32* %10
%15 = call i32 @clear_buf(i8* %14)
%16 = load i8*, i8** %3
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %17, i32** %7
%18 = load i8*, i8** %4
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %19, i32** %8
br label %20
20: ; preds = %66, %2
%21 = trunc i64 %12 to i32
%22 = load i32*, i32** %7
%23 = call i64 @fgets(i8* %14, i32 %21, i32* %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %68
25: ; preds = %20
br label %26
26: ; preds = %39, %25
%27 = load i32, i32* %10
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %14, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp ne i32 %31, 10
br i1 %32, label %33, label %37
33: ; preds = %26
%34 = load i32, i32* %10
%35 = load i32, i32* @BUFSIZ
%36 = icmp slt i32 %34, %35
br label %37
37: ; preds = %33, %26
%38 = phi i1 [ false, %26 ], [ %36, %33 ]
br i1 %38, label %39, label %42
39: ; preds = %37
%40 = load i32, i32* %10
%41 = add nsw i32 %40, 1
store i32 %41, i32* %10
br label %26
42: ; preds = %37
store i32 0, i32* %9
br label %43
43: ; preds = %63, %42
%44 = load i32, i32* %9
%45 = icmp slt i32 %44, 10
br i1 %45, label %46, label %66
46: ; preds = %43
%47 = load i32, i32* %9
%48 = add nsw i32 %47, 48
%49 = trunc i32 %48 to i8
%50 = load i32, i32* %10
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %14, i64 %51
store i8 %49, i8* %52
%53 = load i32, i32* %10
%54 = add nsw i32 %53, 1
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %14, i64 %55
store i8 10, i8* %56
%57 = load i32, i32* %10
%58 = add nsw i32 %57, 2
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %14, i64 %59
store i8 0, i8* %60
%61 = load i32*, i32** %8
%62 = call i32 @fprintf(i32* %61, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %14)
br label %63
63: ; preds = %46
%64 = load i32, i32* %9
%65 = add nsw i32 %64, 1
store i32 %65, i32* %9
br label %43
66: ; preds = %43
store i32 0, i32* %10
%67 = call i32 @clear_buf(i8* %14)
br label %20
68: ; preds = %20
%69 = load i32*, i32** %7
%70 = call i32 @fclose(i32* %69)
%71 = load i32*, i32** %8
%72 = call i32 @fclose(i32* %71)
%73 = load i8*, i8** %5
ret i32 0
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"w+\00"
define i32 @append_numbers(i8* nocapture %0, i8* nocapture %1) {
%3 = load i32, i32* @BUFSIZ
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = call i32 @clear_buf(i8* %5)
%7 = call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%9 = call i64 @fgets(i8* %5, i32 %3, i32* %7)
%10 = icmp eq i64 %9, 0
br i1 %10, label %44, label %11
11: ; preds = %2, %22
%12 = load i32, i32* @BUFSIZ
%13 = sext i32 %12 to i64
br label %14
14: ; preds = %14, %11
%15 = phi i64 [ %21, %14 ], [ 0, %11 ]
%16 = getelementptr inbounds i8, i8* %5, i64 %15
%17 = load i8, i8* %16
%18 = icmp ne i8 %17, 10
%19 = icmp slt i64 %15, %13
%20 = select i1 %18, i1 %19, i1 false
%21 = add nuw nsw i64 %15, 1
br i1 %20, label %14, label %22
22: ; preds = %14
%23 = and i64 %15, 4294967295
%24 = getelementptr inbounds i8, i8* %5, i64 %23
%25 = add nuw i64 %15, 1
%26 = and i64 %25, 4294967295
%27 = getelementptr inbounds i8, i8* %5, i64 %26
%28 = add nuw i64 %15, 2
%29 = and i64 %28, 4294967295
%30 = getelementptr inbounds i8, i8* %5, i64 %29
store i8 48, i8* %24
store i8 10, i8* %27
store i8 0, i8* %30
%31 = call i32 @fputs(i8* %5, i32* %8)
store i8 49, i8* %24
store i8 10, i8* %27
store i8 0, i8* %30
%32 = call i32 @fputs(i8* %5, i32* %8)
store i8 50, i8* %24
store i8 10, i8* %27
store i8 0, i8* %30
%33 = call i32 @fputs(i8* %5, i32* %8)
store i8 51, i8* %24
store i8 10, i8* %27
store i8 0, i8* %30
%34 = call i32 @fputs(i8* %5, i32* %8)
store i8 52, i8* %24
store i8 10, i8* %27
store i8 0, i8* %30
%35 = call i32 @fputs(i8* %5, i32* %8)
store i8 53, i8* %24
store i8 10, i8* %27
store i8 0, i8* %30
%36 = call i32 @fputs(i8* %5, i32* %8)
store i8 54, i8* %24
store i8 10, i8* %27
store i8 0, i8* %30
%37 = call i32 @fputs(i8* %5, i32* %8)
store i8 55, i8* %24
store i8 10, i8* %27
store i8 0, i8* %30
%38 = call i32 @fputs(i8* %5, i32* %8)
store i8 56, i8* %24
store i8 10, i8* %27
store i8 0, i8* %30
%39 = call i32 @fputs(i8* %5, i32* %8)
store i8 57, i8* %24
store i8 10, i8* %27
store i8 0, i8* %30
%40 = call i32 @fputs(i8* %5, i32* %8)
%41 = call i32 @clear_buf(i8* %5)
%42 = call i64 @fgets(i8* %5, i32 %3, i32* %7)
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %11
44: ; preds = %22, %2
%45 = call i32 @fclose(i32* %7)
%46 = call i32 @fclose(i32* %8)
ret i32 0
}