#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__ ferror(int /*<<< orphan*/);
char *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ puts(char *);
scalar_t__ sscanf(char *, char *, char *, int *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strcat(char *, char *);
int strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
void myMapLines(void) {
  char line[10000];
  char friend[10000];
  char key[10000];
  char output[2 * 10000];
  char *result;
  int n = 0;
  int idx = 0;
  int comparison;
  int friend_offset;
  while ((result = fgets(line, 10000, stdin)) != NULL) {
    if (ferror(stdin)) {
      perror("Error reading stdin.");
    }
    while (line[idx]) {
      if (line[idx] == '\n') {
        line[idx] = ' ';
      }
      idx++;
    }
    idx = 0;
    sscanf(&line[idx], "%s %n", key, &n);
    idx += n;
    friend_offset = idx;
    while (sscanf(&line[idx], "%s %n", friend, &n) > 0) {
      idx += n;
      comparison = strcmp(key, friend);
      if (comparison > 0) {
        strcpy(output, friend);
        strcat(output, " ");
        strcat(output, key);
        strcat(output, "\t");
        strcat(output, &line[friend_offset]);
      }
      if (comparison < 0) {
        strcpy(output, key);
        strcat(output, " ");
        strcat(output, friend);
        strcat(output, "\t");
        strcat(output, &line[friend_offset]);
      }
      puts(output);
    }
    idx = 0;
  }
  if (ferror(stdin)) {
    perror("Error reading stdin.");
  }
}


x86 assembly (clang, -O0):
<myMapLines>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc370,%rsp
movl   $0x0,-0xc35c(%rbp)
movl   $0x0,-0xc360(%rbp)
lea    -0x2710(%rbp),%rdi
mov    0x2e3b(%rip),%rax
mov    (%rax),%edx
mov    $0x2710,%esi
call   1060 <fgets@plt>
mov    %rax,-0xc358(%rbp)
cmp    $0x0,%rax
je     1402 <myMapLines+0x282>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
call   1050 <ferror@plt>
cmp    $0x0,%rax
je     11ee <myMapLines+0x6e>
lea    0xe17(%rip),%rdi
call   1090 <perror@plt>
jmp    11f3 <myMapLines+0x73>
movslq -0xc360(%rbp),%rax
cmpb   $0x0,-0x2710(%rbp,%rax,1)
je     1243 <myMapLines+0xc3>
movslq -0xc360(%rbp),%rax
movsbl -0x2710(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    122f <myMapLines+0xaf>
movslq -0xc360(%rbp),%rax
movb   $0x20,-0x2710(%rbp,%rax,1)
20
mov    -0xc360(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc360(%rbp)
jmp    11f3 <myMapLines+0x73>
movl   $0x0,-0xc360(%rbp)
movslq -0xc360(%rbp),%rax
lea    -0x2710(%rbp),%rdi
add    %rax,%rdi
lea    -0x7530(%rbp),%rdx
lea    0xda9(%rip),%rsi
lea    -0xc35c(%rbp),%rcx
call   1080 <sscanf@plt>
mov    -0xc35c(%rbp),%eax
add    -0xc360(%rbp),%eax
mov    %eax,-0xc360(%rbp)
mov    -0xc360(%rbp),%eax
mov    %eax,-0xc368(%rbp)
movslq -0xc360(%rbp),%rax
lea    -0x2710(%rbp),%rdi
add    %rax,%rdi
lea    -0x4e20(%rbp),%rdx
lea    0xd60(%rip),%rsi
lea    -0xc35c(%rbp),%rcx
call   1080 <sscanf@plt>
cmp    $0x0,%rax
jle    13f3 <myMapLines+0x273>
mov    -0xc35c(%rbp),%eax
add    -0xc360(%rbp),%eax
mov    %eax,-0xc360(%rbp)
lea    -0x7530(%rbp),%rdi
lea    -0x4e20(%rbp),%rsi
call   1070 <strcmp@plt>
mov    %eax,-0xc364(%rbp)
cmpl   $0x0,-0xc364(%rbp)
jle    136c <myMapLines+0x1ec>
lea    -0xc350(%rbp),%rdi
lea    -0x4e20(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0xc350(%rbp),%rdi
lea    0xcf7(%rip),%rsi
call   10a0 <strcat@plt>
lea    -0xc350(%rbp),%rdi
lea    -0x7530(%rbp),%rsi
call   10a0 <strcat@plt>
lea    -0xc350(%rbp),%rdi
lea    0xcd3(%rip),%rsi
call   10a0 <strcat@plt>
lea    -0xc350(%rbp),%rdi
movslq -0xc368(%rbp),%rax
lea    -0x2710(%rbp),%rsi
add    %rax,%rsi
call   10a0 <strcat@plt>
cmpl   $0x0,-0xc364(%rbp)
jge    13e2 <myMapLines+0x262>
lea    -0xc350(%rbp),%rdi
lea    -0x7530(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0xc350(%rbp),%rdi
lea    0xc81(%rip),%rsi
call   10a0 <strcat@plt>
lea    -0xc350(%rbp),%rdi
lea    -0x4e20(%rbp),%rsi
call   10a0 <strcat@plt>
lea    -0xc350(%rbp),%rdi
lea    0xc5d(%rip),%rsi
call   10a0 <strcat@plt>
lea    -0xc350(%rbp),%rdi
movslq -0xc368(%rbp),%rax
lea    -0x2710(%rbp),%rsi
add    %rax,%rsi
call   10a0 <strcat@plt>
lea    -0xc350(%rbp),%rdi
call   1040 <puts@plt>
jmp    1296 <myMapLines+0x116>
movl   $0x0,-0xc360(%rbp)
jmp    119f <myMapLines+0x1f>
mov    0x2bdf(%rip),%rax
mov    (%rax),%edi
call   1050 <ferror@plt>
cmp    $0x0,%rax
je     1426 <myMapLines+0x2a6>
lea    0xbdf(%rip),%rdi
call   1090 <perror@plt>
add    $0xc370,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<myMapLines>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xc368,%rsp
movl   $0x0,0xc(%rsp)
mov    0x2e48(%rip),%r14
mov    (%r14),%edx
lea    0x10(%rsp),%r12
mov    %r12,%rdi
mov    $0x2710,%esi
call   1060 <fgets@plt>
test   %rax,%rax
je     131c <myMapLines+0x19c>
lea    0x2720(%rsp),%r15
lea    0x4e30(%rsp),%rbx
lea    0x7540(%rsp),%rbp
jmp    1205 <myMapLines+0x85>
nopl   0x0(%rax,%rax,1)
mov    0x2e01(%rip),%r14
mov    (%r14),%edx
lea    0x10(%rsp),%r12
mov    %r12,%rdi
mov    $0x2710,%esi
call   1060 <fgets@plt>
test   %rax,%rax
je     131c <myMapLines+0x19c>
mov    (%r14),%edi
call   1050 <ferror@plt>
test   %rax,%rax
jne    130b <myMapLines+0x18b>
mov    %r12,%rax
jmp    1227 <myMapLines+0xa7>
nopl   0x0(%rax,%rax,1)
movb   $0x20,(%rax)
add    $0x1,%rax
movzbl (%rax),%ecx
cmp    $0xa,%cl
je     1220 <myMapLines+0xa0>
test   %cl,%cl
jne    1223 <myMapLines+0xa3>
mov    %r12,%rdi
lea    0xdd8(%rip),%r13
mov    %r13,%rsi
mov    %r15,%rdx
lea    0xc(%rsp),%rcx
call   1080 <sscanf@plt>
movslq 0xc(%rsp),%r12
lea    (%rsp,%r12,1),%r14
add    $0x10,%r14
mov    %r14,%rdi
mov    %r13,%rsi
jmp    12c3 <myMapLines+0x143>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbp,%rdi
call   1030 <strcpy@plt>
mov    %rbp,%rdi
lea    0xd99(%rip),%rsi
call   10a0 <strcat@plt>
mov    %rbp,%rdi
mov    %r13,%rsi
call   10a0 <strcat@plt>
mov    %rbp,%rdi
lea    0xd81(%rip),%rsi
call   10a0 <strcat@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   10a0 <strcat@plt>
mov    %rbp,%rdi
call   1040 <puts@plt>
lea    (%rsp,%r12,1),%rdi
add    $0x10,%rdi
lea    0xd52(%rip),%rsi
mov    %rbx,%rdx
lea    0xc(%rsp),%rcx
call   1080 <sscanf@plt>
test   %rax,%rax
jle    11e0 <myMapLines+0x60>
movslq 0xc(%rsp),%rax
movslq %r12d,%r12
add    %rax,%r12
mov    %r15,%rdi
mov    %rbx,%rsi
call   1070 <strcmp@plt>
mov    %rbx,%rsi
mov    %r15,%r13
test   %eax,%eax
jg     1270 <myMapLines+0xf0>
mov    %r15,%rsi
mov    %rbx,%r13
js     1270 <myMapLines+0xf0>
jmp    12ac <myMapLines+0x12c>
lea    0xcee(%rip),%rdi
call   1090 <perror@plt>
jmp    1216 <myMapLines+0x96>
mov    (%r14),%edi
call   1050 <ferror@plt>
test   %rax,%rax
jne    133b <myMapLines+0x1bb>
add    $0xc368,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcbe(%rip),%rdi
call   1090 <perror@plt>
jmp    1329 <myMapLines+0x1a9>

LLVM IR (-O0):
@stdin = global i32 0
@.str = [21 x i8] c"Error reading stdin.\00"
@.str.1 = [6 x i8] c"%s %n\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [2 x i8] c"\09\00"
define void @myMapLines() {
%1 = alloca [10000 x i8]
%2 = alloca [10000 x i8]
%3 = alloca [10000 x i8]
%4 = alloca [20000 x i8]
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %6
store i32 0, i32* %7
br label %10
10: ; preds = %106, %0
%11 = getelementptr inbounds [10000 x i8], [10000 x i8]* %1, i64 0, i64 0
%12 = load i32, i32* @stdin
%13 = call i8* @fgets(i8* %11, i32 10000, i32 %12)
store i8* %13, i8** %5
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %107
15: ; preds = %10
%16 = load i32, i32* @stdin
%17 = call i64 @ferror(i32 %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %21
21: ; preds = %19, %15
br label %22
22: ; preds = %39, %21
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [10000 x i8], [10000 x i8]* %1, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = icmp ne i8 %26, 0
br i1 %27, label %28, label %42
28: ; preds = %22
%29 = load i32, i32* %7
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [10000 x i8], [10000 x i8]* %1, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 10
br i1 %34, label %35, label %39
35: ; preds = %28
%36 = load i32, i32* %7
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [10000 x i8], [10000 x i8]* %1, i64 0, i64 %37
store i8 32, i8* %38
br label %39
39: ; preds = %35, %28
%40 = load i32, i32* %7
%41 = add nsw i32 %40, 1
store i32 %41, i32* %7
br label %22
42: ; preds = %22
store i32 0, i32* %7
%43 = load i32, i32* %7
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [10000 x i8], [10000 x i8]* %1, i64 0, i64 %44
%46 = getelementptr inbounds [10000 x i8], [10000 x i8]* %3, i64 0, i64 0
%47 = call i64 @sscanf(i8* %45, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %46, i32* %6)
%48 = load i32, i32* %6
%49 = load i32, i32* %7
%50 = add nsw i32 %49, %48
store i32 %50, i32* %7
%51 = load i32, i32* %7
store i32 %51, i32* %9
br label %52
52: ; preds = %103, %42
%53 = load i32, i32* %7
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [10000 x i8], [10000 x i8]* %1, i64 0, i64 %54
%56 = getelementptr inbounds [10000 x i8], [10000 x i8]* %2, i64 0, i64 0
%57 = call i64 @sscanf(i8* %55, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %56, i32* %6)
%58 = icmp sgt i64 %57, 0
br i1 %58, label %59, label %106
59: ; preds = %52
%60 = load i32, i32* %6
%61 = load i32, i32* %7
%62 = add nsw i32 %61, %60
store i32 %62, i32* %7
%63 = getelementptr inbounds [10000 x i8], [10000 x i8]* %3, i64 0, i64 0
%64 = getelementptr inbounds [10000 x i8], [10000 x i8]* %2, i64 0, i64 0
%65 = call i32 @strcmp(i8* %63, i8* %64)
store i32 %65, i32* %8
%66 = load i32, i32* %8
%67 = icmp sgt i32 %66, 0
br i1 %67, label %68, label %84
68: ; preds = %59
%69 = getelementptr inbounds [20000 x i8], [20000 x i8]* %4, i64 0, i64 0
%70 = getelementptr inbounds [10000 x i8], [10000 x i8]* %2, i64 0, i64 0
%71 = call i32 @strcpy(i8* %69, i8* %70)
%72 = getelementptr inbounds [20000 x i8], [20000 x i8]* %4, i64 0, i64 0
%73 = call i32 @strcat(i8* %72, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%74 = getelementptr inbounds [20000 x i8], [20000 x i8]* %4, i64 0, i64 0
%75 = getelementptr inbounds [10000 x i8], [10000 x i8]* %3, i64 0, i64 0
%76 = call i32 @strcat(i8* %74, i8* %75)
%77 = getelementptr inbounds [20000 x i8], [20000 x i8]* %4, i64 0, i64 0
%78 = call i32 @strcat(i8* %77, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%79 = getelementptr inbounds [20000 x i8], [20000 x i8]* %4, i64 0, i64 0
%80 = load i32, i32* %9
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds [10000 x i8], [10000 x i8]* %1, i64 0, i64 %81
%83 = call i32 @strcat(i8* %79, i8* %82)
br label %84
84: ; preds = %68, %59
%85 = load i32, i32* %8
%86 = icmp slt i32 %85, 0
br i1 %86, label %87, label %103
87: ; preds = %84
%88 = getelementptr inbounds [20000 x i8], [20000 x i8]* %4, i64 0, i64 0
%89 = getelementptr inbounds [10000 x i8], [10000 x i8]* %3, i64 0, i64 0
%90 = call i32 @strcpy(i8* %88, i8* %89)
%91 = getelementptr inbounds [20000 x i8], [20000 x i8]* %4, i64 0, i64 0
%92 = call i32 @strcat(i8* %91, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%93 = getelementptr inbounds [20000 x i8], [20000 x i8]* %4, i64 0, i64 0
%94 = getelementptr inbounds [10000 x i8], [10000 x i8]* %2, i64 0, i64 0
%95 = call i32 @strcat(i8* %93, i8* %94)
%96 = getelementptr inbounds [20000 x i8], [20000 x i8]* %4, i64 0, i64 0
%97 = call i32 @strcat(i8* %96, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%98 = getelementptr inbounds [20000 x i8], [20000 x i8]* %4, i64 0, i64 0
%99 = load i32, i32* %9
%100 = sext i32 %99 to i64
%101 = getelementptr inbounds [10000 x i8], [10000 x i8]* %1, i64 0, i64 %100
%102 = call i32 @strcat(i8* %98, i8* %101)
br label %103
103: ; preds = %87, %84
%104 = getelementptr inbounds [20000 x i8], [20000 x i8]* %4, i64 0, i64 0
%105 = call i32 @puts(i8* %104)
br label %52
106: ; preds = %52
store i32 0, i32* %7
br label %10
107: ; preds = %10
%108 = load i32, i32* @stdin
%109 = call i64 @ferror(i32 %108)
%110 = icmp ne i64 %109, 0
br i1 %110, label %111, label %113
111: ; preds = %107
%112 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %113
113: ; preds = %111, %107
ret void
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [21 x i8] c"Error reading stdin.\00"
@.str.1 = [6 x i8] c"%s %n\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [2 x i8] c"\09\00"
define void @myMapLines() {
%1 = alloca [10000 x i8]
%2 = alloca [10000 x i8]
%3 = alloca [10000 x i8]
%4 = alloca [20000 x i8]
%5 = alloca i32
%6 = getelementptr inbounds [10000 x i8], [10000 x i8]* %1, i64 0, i64 0
%7 = getelementptr inbounds [10000 x i8], [10000 x i8]* %2, i64 0, i64 0
%8 = getelementptr inbounds [10000 x i8], [10000 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds [20000 x i8], [20000 x i8]* %4, i64 0, i64 0
%10 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%11 = load i32, i32* @stdin
%12 = call i8* @fgets(i8* %6, i32 10000, i32 %11)
%13 = icmp eq i8* %12, null
br i1 %13, label %61, label %18
14: ; preds = %55, %32
%15 = load i32, i32* @stdin
%16 = call i8* @fgets(i8* %6, i32 10000, i32 %15)
%17 = icmp eq i8* %16, null
br i1 %17, label %61, label %18
18: ; preds = %0, %14
%19 = load i32, i32* @stdin
%20 = call i64 @ferror(i32 %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %18
%23 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %24
24: ; preds = %22, %18
br label %25
25: ; preds = %24, %30
%26 = phi i64 [ %31, %30 ], [ 0, %24 ]
%27 = getelementptr inbounds [10000 x i8], [10000 x i8]* %1, i64 0, i64 %26
%28 = load i8, i8* %27
switch i8 %28, label %30 [
i8 0, label %32
i8 10, label %29
]
29: ; preds = %25
store i8 32, i8* %27
br label %30
30: ; preds = %25, %29
%31 = add nuw i64 %26, 1
br label %25
32: ; preds = %25
%33 = call i64 @sscanf(i8* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %8, i32* %5)
%34 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [10000 x i8], [10000 x i8]* %1, i64 0, i64 %35
%37 = call i64 @sscanf(i8* %36, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %7, i32* %5)
%38 = icmp sgt i64 %37, 0
br i1 %38, label %39, label %14
39: ; preds = %32, %55
%40 = phi i32 [ %42, %55 ], [ %34, %32 ]
%41 = load i32, i32* %5
%42 = add nsw i32 %41, %40
%43 = call i32 @strcmp(i8* %8, i8* %7)
%44 = icmp sgt i32 %43, 0
br i1 %44, label %47, label %45
45: ; preds = %39
%46 = icmp slt i32 %43, 0
br i1 %46, label %47, label %55
47: ; preds = %45, %39
%48 = phi i8* [ %7, %39 ], [ %8, %45 ]
%49 = phi i8* [ %8, %39 ], [ %7, %45 ]
%50 = call i32 @strcpy(i8* %9, i8* %48)
%51 = call i32 @strcat(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%52 = call i32 @strcat(i8* %9, i8* %49)
%53 = call i32 @strcat(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%54 = call i32 @strcat(i8* %9, i8* %36)
br label %55
55: ; preds = %47, %45
%56 = call i32 @puts(i8* %9)
%57 = sext i32 %42 to i64
%58 = getelementptr inbounds [10000 x i8], [10000 x i8]* %1, i64 0, i64 %57
%59 = call i64 @sscanf(i8* %58, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %7, i32* %5)
%60 = icmp sgt i64 %59, 0
br i1 %60, label %39, label %14
61: ; preds = %14, %0
%62 = load i32, i32* @stdin
%63 = call i64 @ferror(i32 %62)
%64 = icmp eq i64 %63, 0
br i1 %64, label %67, label %65
65: ; preds = %61
%66 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %67
67: ; preds = %65, %61
ret void
}