#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__ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, char *);
int /*<<< orphan*/ stdin;
int strlen(char *);
int main(int argc, char **argv) {
  char *addition = "";
  if (argc > 1) {
    addition = argv[1];
  }
  char str[80];
  int len;
  while (fgets(str, 10, stdin)) {
    len = strlen(str);
    if (str[len - 1] == '\n') {
      str[len - 1] = 0;
    }
    printf("%s%s\n", str, addition);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xeb5(%rip),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    116a <main+0x3a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    116f <main+0x3f>
lea    -0x70(%rbp),%rdi
mov    0x2e6e(%rip),%rax
mov    (%rax),%edx
mov    $0xa,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11d8 <main+0xa8>
lea    -0x70(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x74(%rbp)
mov    -0x74(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x70(%rbp,%rax,1),%eax
cmp    $0xa,%eax
jne    11bf <main+0x8f>
mov    -0x74(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x70(%rbp,%rax,1)
lea    -0x70(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe32(%rip),%rdi
call   1040 <printf@plt>
jmp    116f <main+0x3f>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x58,%rsp
cmp    $0x2,%edi
jl     1146 <main+0x16>
mov    0x8(%rsi),%r14
jmp    114d <main+0x1d>
lea    0xeb8(%rip),%r14
mov    0x2e94(%rip),%r12
mov    (%r12),%edx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0xa,%esi
call   1050 <fgets@plt>
test   %rax,%rax
je     11bc <main+0x8c>
lea    0xe8c(%rip),%r15
jmp    11a4 <main+0x74>
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1040 <printf@plt>
mov    (%r12),%edx
mov    %rbx,%rdi
mov    $0xa,%esi
call   1050 <fgets@plt>
test   %rax,%rax
je     11bc <main+0x8c>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%rbx,1)
jne    1180 <main+0x50>
movb   $0x0,-0x1(%rsp,%rax,1)
jmp    1180 <main+0x50>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@stdin = global i32 0
@.str.1 = [6 x i8] c"%s%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [80 x i8]
%4 = icmp sgt i32 %0, 1
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
br label %8
8: ; preds = %5, %2
%9 = phi i8* [ %7, %5 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %2 ]
%10 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%11 = load i32, i32* @stdin
%12 = call i64 @fgets(i8* %10, i32 10, i32 %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %27, label %14
14: ; preds = %8, %22
%15 = call i32 @strlen(i8* %10)
%16 = add nsw i32 %15, -1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 10
br i1 %20, label %21, label %22
21: ; preds = %14
store i8 0, i8* %18
br label %22
22: ; preds = %21, %14
%23 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %10, i8* %9)
%24 = load i32, i32* @stdin
%25 = call i64 @fgets(i8* %10, i32 10, i32 %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %14
27: ; preds = %22, %8
ret i32 0
}