#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 */

/* Variables and functions */
scalar_t__ get_line(char *, int /*<<< orphan*/);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stdin;
int add_line(char *line, int add_after_line) {
  char buffer[1024];
  int x = 0;
  while (get_line(buffer, stdin)) {
    puts(buffer);
    if (x == add_after_line) {
      puts(line);
      x = 0;
    } else
      x++;
  }
  return 1;
}


x86 assembly (clang, -O0):
<add_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x414(%rbp)
lea    -0x410(%rbp),%rdi
mov    0x2e9e(%rip),%rax
mov    (%rax),%esi
call   1040 <get_line@plt>
cmp    $0x0,%rax
je     11a2 <add_line+0x82>
lea    -0x410(%rbp),%rdi
call   1030 <puts@plt>
mov    -0x414(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    118e <add_line+0x6e>
mov    -0x8(%rbp),%rdi
call   1030 <puts@plt>
movl   $0x0,-0x414(%rbp)
jmp    119d <add_line+0x7d>
mov    -0x414(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x414(%rbp)
jmp    113c <add_line+0x1c>
mov    $0x1,%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_line>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    %esi,%r12d
mov    %rdi,%r14
mov    0x2eac(%rip),%r15
mov    (%r15),%esi
mov    %rsp,%rdi
call   1040 <get_line@plt>
test   %rax,%rax
je     118c <add_line+0x6c>
xor    %ebp,%ebp
mov    %rsp,%rbx
jmp    1173 <add_line+0x53>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%ebp
mov    (%r15),%esi
mov    %rbx,%rdi
call   1040 <get_line@plt>
test   %rax,%rax
je     118c <add_line+0x6c>
mov    %rbx,%rdi
call   1030 <puts@plt>
cmp    %r12d,%ebp
jne    1160 <add_line+0x40>
mov    %r14,%rdi
call   1030 <puts@plt>
xor    %ebp,%ebp
jmp    1163 <add_line+0x43>
mov    $0x1,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
define i32 @add_line(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [1024 x i8]
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %6
br label %7
7: ; preds = %24, %2
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%9 = load i32, i32* @stdin
%10 = call i64 @get_line(i8* %8, i32 %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %25
12: ; preds = %7
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%14 = call i32 @puts(i8* %13)
%15 = load i32, i32* %6
%16 = load i32, i32* %4
%17 = icmp eq i32 %15, %16
br i1 %17, label %18, label %21
18: ; preds = %12
%19 = load i8*, i8** %3
%20 = call i32 @puts(i8* %19)
store i32 0, i32* %6
br label %24
21: ; preds = %12
%22 = load i32, i32* %6
%23 = add nsw i32 %22, 1
store i32 %23, i32* %6
br label %24
24: ; preds = %21, %18
br label %7
25: ; preds = %7
ret i32 1
}

LLVM IR (-O2):
@stdin = global i32 0
define i32 @add_line(i8* nocapture %0, i32 %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @stdin
%6 = call i64 @get_line(i8* %4, i32 %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %21, label %8
8: ; preds = %2, %16
%9 = phi i32 [ %17, %16 ], [ 0, %2 ]
%10 = call i32 @puts(i8* %4)
%11 = icmp eq i32 %9, %1
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = call i32 @puts(i8* dereferenceable(1) %0)
br label %16
14: ; preds = %8
%15 = add nsw i32 %9, 1
br label %16
16: ; preds = %14, %12
%17 = phi i32 [ 0, %12 ], [ %15, %14 ]
%18 = load i32, i32* @stdin
%19 = call i64 @get_line(i8* %4, i32 %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %8
21: ; preds = %16, %2
ret i32 1
}