#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*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
char getchar();
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  char ch, buf[50];
  unsigned i = 0;
  printf("Type a string: ");
  while ((ch = getchar()) != '\n') {
    if (i < 50 - 1)
      buf[i++] = ch;
    else {
      printf("Sorry, the string is too large.\n");
      exit(EXIT_FAILURE);
    }
  }
  printf("%s\n", buf);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x44(%rbp)
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x5(%rbp)
movsbl %al,%eax
cmp    $0xa,%eax
je     11ae <main+0x7e>
cmpl   $0x31,-0x44(%rbp)
jae    118d <main+0x5d>
mov    -0x5(%rbp),%cl
mov    -0x44(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x44(%rbp)
mov    %eax,%eax
mov    %cl,-0x40(%rbp,%rax,1)
jmp    11a9 <main+0x79>
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
jmp    1154 <main+0x24>
lea    -0x40(%rbp),%rsi
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e11(%rip),%rax
mov    (%rax),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x40,%rsp
lea    0xeb4(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%al
je     1178 <main+0x38>
xor    %ebx,%ebx
cmp    $0x31,%rbx
je     118f <main+0x4f>
mov    %al,(%rsp,%rbx,1)
add    $0x1,%rbx
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%al
jne    1160 <main+0x20>
mov    %rsp,%rdi
call   1030 <puts@plt>
mov    0x2e51(%rip),%rax
mov    (%rax),%eax
add    $0x40,%rsp
pop    %rbx
ret
lea    0xe7a(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"Type a string: \00"
@.str.1 = [33 x i8] c"Sorry, the string is too large.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [4 x i8] c"%s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca [50 x i8]
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %23, %0
%7 = call signext i8 (...) @getchar()
store i8 %7, i8* %2
%8 = sext i8 %7 to i32
%9 = icmp ne i32 %8, 10
br i1 %9, label %10, label %24
10: ; preds = %6
%11 = load i32, i32* %4
%12 = icmp ult i32 %11, 49
br i1 %12, label %13, label %19
13: ; preds = %10
%14 = load i8, i8* %2
%15 = load i32, i32* %4
%16 = add i32 %15, 1
store i32 %16, i32* %4
%17 = zext i32 %15 to i64
%18 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 %17
store i8 %14, i8* %18
br label %23
19: ; preds = %10
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %13
br label %6
24: ; preds = %6
%25 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %25)
%27 = load i32, i32* @EXIT_SUCCESS
ret i32 %27
}

LLVM IR (-O2):
@.str = [16 x i8] c"Type a string: \00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
@str = [32 x i8] c"Sorry, the string is too large.\00"
define i32 @main() {
%1 = alloca [50 x i8]
%2 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%4 = tail call signext i8 (...) @getchar()
%5 = icmp eq i8 %4, 10
br i1 %5, label %19, label %6
6: ; preds = %0, %10
%7 = phi i64 [ %11, %10 ], [ 0, %0 ]
%8 = phi i8 [ %13, %10 ], [ %4, %0 ]
%9 = icmp eq i64 %7, 49
br i1 %9, label %15, label %10
10: ; preds = %6
%11 = add nuw nsw i64 %7, 1
%12 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 %7
store i8 %8, i8* %12
%13 = tail call signext i8 (...) @getchar()
%14 = icmp eq i8 %13, 10
br i1 %14, label %19, label %6
15: ; preds = %6
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = tail call i32 @exit(i32 %17)
unreachable
19: ; preds = %10, %0
%20 = call i32 @puts(i8* %2)
%21 = load i32, i32* @EXIT_SUCCESS
ret i32 %21
}