#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 */
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
char getchar();
int /*<<< orphan*/ insert_line(char *, int);
int /*<<< orphan*/ stdin;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strtok(char *, char *);
int /*<<< orphan*/ ungetc(char, int /*<<< orphan*/);
void insert_lines(int current_line) {
  int lines_inputted = 0;
  char input_line[80];
  char c;
  while (1) {
    c = getchar();
    if (c != '\n') {
      ungetc(c, stdin);
      break;
    }
  }
  while (1) {
    fgets(input_line, 80, stdin);
    if (strcmp(input_line, ".\n") == 0) {
      break;
    } else if (strcmp(input_line, "\n") == 0) {
      input_line[0] = '\0';
    } else {
      strtok(input_line, "\n");
    }
    insert_line(input_line, current_line + lines_inputted);
    lines_inputted++;
  }
}


x86 assembly (clang, -O0):
<insert_lines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,-0x61(%rbp)
movsbl -0x61(%rbp),%eax
cmp    $0xa,%eax
je     11a2 <insert_lines+0x42>
mov    -0x61(%rbp),%al
mov    0x2e55(%rip),%rcx
mov    (%rcx),%esi
movsbl %al,%edi
call   1060 <ungetc@plt>
jmp    11a7 <insert_lines+0x47>
jmp    1172 <insert_lines+0x12>
jmp    11ac <insert_lines+0x4c>
lea    -0x60(%rbp),%rdi
mov    0x2e31(%rip),%rax
mov    (%rax),%edx
mov    $0x50,%esi
call   1030 <fgets@plt>
lea    -0x60(%rbp),%rdi
lea    0xe32(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11e2 <insert_lines+0x82>
jmp    1237 <insert_lines+0xd7>
lea    -0x60(%rbp),%rdi
lea    0xe14(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1205 <insert_lines+0xa5>
movb   $0x0,-0x60(%rbp)
jmp    1215 <insert_lines+0xb5>
lea    -0x60(%rbp),%rdi
lea    0xdf1(%rip),%rsi
call   1070 <strtok@plt>
jmp    121a <insert_lines+0xba>
lea    -0x60(%rbp),%rdi
mov    -0x4(%rbp),%esi
add    -0x8(%rbp),%esi
call   1080 <insert_line@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11ac <insert_lines+0x4c>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<insert_lines>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x50,%rsp
mov    %edi,%ebx
nop
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%al
je     1170 <insert_lines+0x10>
mov    0x2e66(%rip),%r13
mov    0x0(%r13),%esi
movsbl %al,%edi
call   1060 <ungetc@plt>
mov    0x0(%r13),%edx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x50,%esi
call   1030 <fgets@plt>
lea    0xe57(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     121f <insert_lines+0xbf>
lea    0xe44(%rip),%r14
mov    %rsp,%r15
lea    0xe39(%rip),%r12
jmp    1209 <insert_lines+0xa9>
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %r14,%rsi
call   1070 <strtok@plt>
mov    %r15,%rdi
mov    %ebx,%esi
call   1080 <insert_line@plt>
mov    0x0(%r13),%edx
mov    %r15,%rdi
mov    $0x50,%esi
call   1030 <fgets@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1040 <strcmp@plt>
add    $0x1,%ebx
test   %rax,%rax
je     121f <insert_lines+0xbf>
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    11d0 <insert_lines+0x70>
movb   $0x0,(%rsp)
jmp    11db <insert_lines+0x7b>
add    $0x50,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [3 x i8] c".\0A\00"
@.str.1 = [2 x i8] c"\0A\00"
define void @insert_lines(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [80 x i8]
%5 = alloca i8
store i32 %0, i32* %2
store i32 0, i32* %3
br label %6
6: ; preds = %1, %15
%7 = call signext i8 (...) @getchar()
store i8 %7, i8* %5
%8 = load i8, i8* %5
%9 = sext i8 %8 to i32
%10 = icmp ne i32 %9, 10
br i1 %10, label %11, label %15
11: ; preds = %6
%12 = load i8, i8* %5
%13 = load i32, i32* @stdin
%14 = call i32 @ungetc(i8 signext %12, i32 %13)
br label %16
15: ; preds = %6
br label %6
16: ; preds = %11
br label %17
17: ; preds = %16, %35
%18 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%19 = load i32, i32* @stdin
%20 = call i32 @fgets(i8* %18, i32 80, i32 %19)
%21 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%22 = call i64 @strcmp(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %17
br label %43
25: ; preds = %17
%26 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%27 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %25
%30 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
store i8 0, i8* %30
br label %34
31: ; preds = %25
%32 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%33 = call i32 @strtok(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %34
34: ; preds = %31, %29
br label %35
35: ; preds = %34
%36 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%37 = load i32, i32* %2
%38 = load i32, i32* %3
%39 = add nsw i32 %37, %38
%40 = call i32 @insert_line(i8* %36, i32 %39)
%41 = load i32, i32* %3
%42 = add nsw i32 %41, 1
store i32 %42, i32* %3
br label %17
43: ; preds = %24
ret void
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [3 x i8] c".\0A\00"
@.str.1 = [2 x i8] c"\0A\00"
define void @insert_lines(i32 %0) {
%2 = alloca [80 x i8]
%3 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
br label %4
4: ; preds = %4, %1
%5 = tail call signext i8 (...) @getchar()
%6 = icmp eq i8 %5, 10
br i1 %6, label %4, label %7
7: ; preds = %4
%8 = load i32, i32* @stdin
%9 = tail call i32 @ungetc(i8 signext %5, i32 %8)
%10 = load i32, i32* @stdin
%11 = call i32 @fgets(i8* %3, i32 80, i32 %10)
%12 = call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %29, label %14
14: ; preds = %7, %21
%15 = phi i32 [ %24, %21 ], [ 0, %7 ]
%16 = call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %14
store i8 0, i8* %3
br label %21
19: ; preds = %14
%20 = call i32 @strtok(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %18, %19
%22 = add nsw i32 %15, %0
%23 = call i32 @insert_line(i8* %3, i32 %22)
%24 = add nuw nsw i32 %15, 1
%25 = load i32, i32* @stdin
%26 = call i32 @fgets(i8* %3, i32 80, i32 %25)
%27 = call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %14
29: ; preds = %21, %7
ret void
}