#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*/ _countof(char *);
char *gets_s(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  char buf[100];
  printf("Enter a string:");
  char *input = gets_s(buf, _countof(buf));
  if (input != NULL) {
    while (*input != '\0')
      printf("%c\n", *input++);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x70(%rbp),%rax
mov    %rax,-0x80(%rbp)
lea    -0x70(%rbp),%rdi
call   1050 <_countof@plt>
mov    -0x80(%rbp),%rdi
mov    %eax,%esi
call   1040 <gets_s@plt>
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x78(%rbp)
je     11ba <main+0x8a>
jmp    1180 <main+0x50>
mov    -0x78(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11b5 <main+0x85>
mov    -0x78(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x78(%rbp)
movsbl (%rax),%esi
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1180 <main+0x50>
jmp    11ba <main+0x8a>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x68,%rsp
lea    0xec2(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1050 <_countof@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <gets_s@plt>
test   %rax,%rax
je     1198 <main+0x68>
mov    %rax,%rbx
mov    (%rax),%al
test   %al,%al
je     1198 <main+0x68>
add    $0x1,%rbx
lea    0xe9d(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl %al,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1180 <main+0x50>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [16 x i8] c"Enter a string:\00"
@.str.1 = [4 x i8] c"%c\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i8]
%3 = alloca i8*
store i32 0, i32* %1
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%7 = call i32 @_countof(i8* %6)
%8 = call i8* @gets_s(i8* %5, i32 %7)
store i8* %8, i8** %3
%9 = load i8*, i8** %3
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %24
11: ; preds = %0
br label %12
12: ; preds = %17, %11
%13 = load i8*, i8** %3
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %12
%18 = load i8*, i8** %3
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %3
%20 = load i8, i8* %18
%21 = sext i8 %20 to i32
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %21)
br label %12
23: ; preds = %12
br label %24
24: ; preds = %23, %0
ret i32 0
}

LLVM IR (-O2):
@.str = [16 x i8] c"Enter a string:\00"
@.str.1 = [4 x i8] c"%c\0A\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 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 = call i32 @_countof(i8* %2)
%5 = call i8* @gets_s(i8* %2, i32 %4)
%6 = icmp eq i8* %5, null
br i1 %6, label %18, label %7
7: ; preds = %0
%8 = load i8, i8* %5
%9 = icmp eq i8 %8, 0
br i1 %9, label %18, label %10
10: ; preds = %7, %10
%11 = phi i8 [ %16, %10 ], [ %8, %7 ]
%12 = phi i8* [ %14, %10 ], [ %5, %7 ]
%13 = sext i8 %11 to i32
%14 = getelementptr inbounds i8, i8* %12, i64 1
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%16 = load i8, i8* %14
%17 = icmp eq i8 %16, 0
br i1 %17, label %18, label %10
18: ; preds = %10, %7, %0
ret i32 0
}