#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 EOF;
int getchar();
int /*<<< orphan*/ printf(char *, char *);
int main(void) {
  int i = 0;
  int lim = 100;
  int c;
  char s[lim];
  while (i < lim - 1) {
    if ((c = getchar()) != '\n') {
      if (c != EOF) {
        s[i] = c;
        ++i;
      } else
        i = lim - 1;
    }
  }
  s[i] = '\0';
  printf("String: %s\n", s);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x64,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11ca <main+0xaa>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x10(%rbp)
cmp    $0xa,%eax
je     11c5 <main+0xa5>
mov    -0x10(%rbp),%eax
mov    0x2e57(%rip),%rcx
cmp    (%rcx),%eax
je     11b7 <main+0x97>
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    %cl,%dl
movslq -0x8(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11c0 <main+0xa0>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11c5 <main+0xa5>
jmp    1163 <main+0x43>
mov    -0x28(%rbp),%rsi
movslq -0x8(%rbp),%rax
movb   $0x0,(%rsi,%rax,1)
lea    0xe23(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x68,%rsp
mov    0x2eba(%rip),%r14
xor    %ebx,%ebx
jmp    1145 <main+0x25>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmp    $0x63,%ebx
jge    1161 <main+0x41>
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0xa,%eax
je     1140 <main+0x20>
cmp    (%r14),%eax
je     1161 <main+0x41>
movslq %ebx,%rbx
mov    %al,(%rsp,%rbx,1)
add    $0x1,%ebx
jmp    1140 <main+0x20>
movb   $0x0,0x63(%rsp)
lea    0xe93(%rip),%rdi
mov    %rsp,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@EOF = global i32 0
@.str = [12 x i8] c"String: %s\0A\00"
define i32 @main() {
%1 = alloca [100 x i8]
br label %2
2: ; preds = %0, %14
%3 = phi i32 [ 0, %0 ], [ %15, %14 ]
%4 = tail call i32 (...) @getchar()
%5 = icmp eq i32 %4, 10
br i1 %5, label %14, label %6
6: ; preds = %2
%7 = load i32, i32* @EOF
%8 = icmp eq i32 %4, %7
br i1 %8, label %17, label %9
9: ; preds = %6
%10 = trunc i32 %4 to i8
%11 = sext i32 %3 to i64
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %11
store i8 %10, i8* %12
%13 = add nsw i32 %3, 1
br label %14
14: ; preds = %9, %2
%15 = phi i32 [ %13, %9 ], [ %3, %2 ]
%16 = icmp slt i32 %15, 99
br i1 %16, label %2, label %17
17: ; preds = %6, %14
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 99
store i8 0, i8* %19
%20 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %18)
ret i32 0
}