#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*/);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
char getchar();
int /*<<< orphan*/ put1(char *);
int /*<<< orphan*/ puts(char *);
char *s_gets(char *, int);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int main(void) {
  char words[14];
  puts("Enter a string: ");
  fgets(words, 14, stdin);
  puts("Your string:");
  fputs(words, stdout);
  put1("Enter another string: ");
  char *words2 = s_gets(words, 14);
  put1("Your string: ");
  put1(words2);
  put1("\n");
  puts("\nEnter strings (empty line to quit):");
  while (fgets(words, 14, stdin) != NULL && words[0] != '\n') {
    int i = 0;
    while (words[i] != '\n' && words[i] != '\0') {
      i++;
    }
    if (words[i] == '\n') {
      words[i] = '\0';
    } else {
      while (getchar() != '\n') {
        continue;
      }
    }
    puts(words);
  }
  puts("Done");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
call   1030 <puts@plt>
lea    -0x12(%rbp),%rdi
mov    0x2e62(%rip),%rax
mov    (%rax),%edx
mov    $0xe,%esi
call   1060 <fgets@plt>
lea    0xe78(%rip),%rdi
call   1030 <puts@plt>
lea    -0x12(%rbp),%rdi
mov    0x2e2f(%rip),%rax
mov    (%rax),%esi
call   1050 <fputs@plt>
lea    0xe67(%rip),%rdi
call   1080 <put1@plt>
lea    -0x12(%rbp),%rdi
mov    $0xe,%esi
call   1040 <s_gets@plt>
mov    %rax,-0x20(%rbp)
lea    0xe60(%rip),%rdi
call   1080 <put1@plt>
mov    -0x20(%rbp),%rdi
call   1080 <put1@plt>
lea    0xe59(%rip),%rdi
call   1080 <put1@plt>
lea    0xe4f(%rip),%rdi
call   1030 <puts@plt>
lea    -0x12(%rbp),%rdi
mov    0x2de2(%rip),%rax
mov    (%rax),%edx
mov    $0xe,%esi
call   1060 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x25(%rbp)
je     1231 <main+0xd1>
movsbl -0x12(%rbp),%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    1241 <main+0xe1>
jmp    12df <main+0x17f>
movl   $0x0,-0x24(%rbp)
movslq -0x24(%rbp),%rax
movsbl -0x12(%rbp,%rax,1),%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x26(%rbp)
je     1271 <main+0x111>
movslq -0x24(%rbp),%rax
movsbl -0x12(%rbp,%rax,1),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x26(%rbp)
mov    -0x26(%rbp),%al
test   $0x1,%al
jne    1281 <main+0x121>
jmp    128f <main+0x12f>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1248 <main+0xe8>
movslq -0x24(%rbp),%rax
movsbl -0x12(%rbp,%rax,1),%eax
cmp    $0xa,%eax
jne    12af <main+0x14f>
movslq -0x24(%rbp),%rax
movb   $0x0,-0x12(%rbp,%rax,1)
jmp    12d1 <main+0x171>
jmp    12b4 <main+0x154>
mov    $0x0,%al
call   1070 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     12cc <main+0x16c>
jmp    12b4 <main+0x154>
jmp    12d1 <main+0x171>
lea    -0x12(%rbp),%rdi
call   1030 <puts@plt>
jmp    11fb <main+0x9b>
lea    0xd84(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xe90(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e6c(%rip),%r15
mov    (%r15),%edx
lea    0x2(%rsp),%r14
mov    %r14,%rdi
mov    $0xe,%esi
call   1060 <fgets@plt>
lea    0xe79(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e34(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1050 <fputs@plt>
lea    0xe69(%rip),%rdi
call   1080 <put1@plt>
mov    %r14,%rdi
mov    $0xe,%esi
call   1040 <s_gets@plt>
mov    %rax,%rbx
lea    0xe64(%rip),%rdi
call   1080 <put1@plt>
mov    %rbx,%rdi
call   1080 <put1@plt>
lea    0xe5e(%rip),%rdi
call   1080 <put1@plt>
lea    0xe54(%rip),%rdi
call   1030 <puts@plt>
mov    (%r15),%edx
mov    %r14,%rdi
mov    $0xe,%esi
call   1060 <fgets@plt>
test   %rax,%rax
je     1271 <main+0x111>
mov    0x2(%rsp),%al
cmp    $0xa,%al
je     1271 <main+0x111>
lea    0x2(%rsp),%rbx
xor    %ecx,%ecx
jmp    1228 <main+0xc8>
nopl   0x0(%rax)
mov    0x3(%rsp,%rcx,1),%al
add    $0x1,%rcx
cmp    $0xa,%al
je     1240 <main+0xe0>
test   %al,%al
jne    1220 <main+0xc0>
xor    %eax,%eax
call   1070 <getchar@plt>
cmp    $0xa,%al
jne    1230 <main+0xd0>
jmp    1247 <main+0xe7>
nopl   (%rax)
mov    %ecx,%eax
movb   $0x0,0x2(%rsp,%rax,1)
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0xe,%esi
call   1060 <fgets@plt>
test   %rax,%rax
je     1271 <main+0x111>
mov    0x2(%rsp),%al
mov    $0x0,%ecx
cmp    $0xa,%al
jne    1228 <main+0xc8>
lea    0xdf2(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [17 x i8] c"Enter a string: \00"
@stdin = global i32 0
@.str.1 = [13 x i8] c"Your string:\00"
@stdout = global i32 0
@.str.2 = [23 x i8] c"Enter another string: \00"
@.str.3 = [14 x i8] c"Your string: \00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [37 x i8] c"\0AEnter strings (empty line to quit):\00"
@.str.6 = [5 x i8] c"Done\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [14 x i8]
%3 = alloca i8*
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 @puts(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 0
%7 = load i32, i32* @stdin
%8 = call i32* @fgets(i8* %6, i32 14, i32 %7)
%9 = call i32 @puts(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%10 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 0
%11 = load i32, i32* @stdout
%12 = call i32 @fputs(i8* %10, i32 %11)
%13 = call i32 @put1(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%14 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 0
%15 = call i8* @s_gets(i8* %14, i32 14)
store i8* %15, i8** %3
%16 = call i32 @put1(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%17 = load i8*, i8** %3
%18 = call i32 @put1(i8* %17)
%19 = call i32 @put1(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%20 = call i32 @puts(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0))
br label %21
21: ; preds = %71, %0
%22 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 0
%23 = load i32, i32* @stdin
%24 = call i32* @fgets(i8* %22, i32 14, i32 %23)
%25 = icmp ne i32* %24, null
br i1 %25, label %26, label %31
26: ; preds = %21
%27 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 0
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 10
br label %31
31: ; preds = %26, %21
%32 = phi i1 [ false, %21 ], [ %30, %26 ]
br i1 %32, label %33, label %74
33: ; preds = %31
store i32 0, i32* %4
br label %34
34: ; preds = %50, %33
%35 = load i32, i32* %4
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 %36
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp ne i32 %39, 10
br i1 %40, label %41, label %48
41: ; preds = %34
%42 = load i32, i32* %4
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 %43
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp ne i32 %46, 0
br label %48
48: ; preds = %41, %34
%49 = phi i1 [ false, %34 ], [ %47, %41 ]
br i1 %49, label %50, label %53
50: ; preds = %48
%51 = load i32, i32* %4
%52 = add nsw i32 %51, 1
store i32 %52, i32* %4
br label %34
53: ; preds = %48
%54 = load i32, i32* %4
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 %55
%57 = load i8, i8* %56
%58 = sext i8 %57 to i32
%59 = icmp eq i32 %58, 10
br i1 %59, label %60, label %64
60: ; preds = %53
%61 = load i32, i32* %4
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 %62
store i8 0, i8* %63
br label %71
64: ; preds = %53
br label %65
65: ; preds = %69, %64
%66 = call signext i8 (...) @getchar()
%67 = sext i8 %66 to i32
%68 = icmp ne i32 %67, 10
br i1 %68, label %69, label %70
69: ; preds = %65
br label %65
70: ; preds = %65
br label %71
71: ; preds = %70, %60
%72 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 0
%73 = call i32 @puts(i8* %72)
br label %21
74: ; preds = %31
%75 = call i32 @puts(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [17 x i8] c"Enter a string: \00"
@stdin = global i32 0
@.str.1 = [13 x i8] c"Your string:\00"
@stdout = global i32 0
@.str.2 = [23 x i8] c"Enter another string: \00"
@.str.3 = [14 x i8] c"Your string: \00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [37 x i8] c"\0AEnter strings (empty line to quit):\00"
@.str.6 = [5 x i8] c"Done\00"
define i32 @main() {
%1 = alloca [14 x i8]
%2 = getelementptr inbounds [14 x i8], [14 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @stdin
%5 = call i32* @fgets(i8* %2, i32 14, i32 %4)
%6 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%7 = load i32, i32* @stdout
%8 = call i32 @fputs(i8* %2, i32 %7)
%9 = call i32 @put1(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%10 = call i8* @s_gets(i8* %2, i32 14)
%11 = call i32 @put1(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%12 = call i32 @put1(i8* %10)
%13 = call i32 @put1(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0))
%15 = load i32, i32* @stdin
%16 = call i32* @fgets(i8* %2, i32 14, i32 %15)
%17 = icmp ne i32* %16, null
%18 = load i8, i8* %2
%19 = icmp ne i8 %18, 10
%20 = select i1 %17, i1 %19, i1 false
br i1 %20, label %21, label %45
21: ; preds = %0, %28
%22 = phi i8 [ %29, %28 ], [ %18, %0 ]
%23 = phi i64 [ %30, %28 ], [ 0, %0 ]
switch i8 %22, label %24 [
i8 10, label %31
i8 0, label %34
]
24: ; preds = %21
%25 = add nuw i64 %23, 1
%26 = getelementptr inbounds [14 x i8], [14 x i8]* %1, i64 0, i64 %25
%27 = load i8, i8* %26
br label %28
28: ; preds = %24, %37
%29 = phi i8 [ %27, %24 ], [ %42, %37 ]
%30 = phi i64 [ %25, %24 ], [ 0, %37 ]
br label %21
31: ; preds = %21
%32 = and i64 %23, 4294967295
%33 = getelementptr inbounds [14 x i8], [14 x i8]* %1, i64 0, i64 %32
store i8 0, i8* %33
br label %37
34: ; preds = %21, %34
%35 = call signext i8 (...) @getchar()
%36 = icmp eq i8 %35, 10
br i1 %36, label %37, label %34
37: ; preds = %34, %31
%38 = call i32 @puts(i8* %2)
%39 = load i32, i32* @stdin
%40 = call i32* @fgets(i8* %2, i32 14, i32 %39)
%41 = icmp ne i32* %40, null
%42 = load i8, i8* %2
%43 = icmp ne i8 %42, 10
%44 = select i1 %41, i1 %43, i1 false
br i1 %44, label %28, label %45
45: ; preds = %37, %0
%46 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
ret i32 0
}