#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*/ printf(char *);
int /*<<< orphan*/ stdin;
int main(void) {
  printf("Press Ctrl+C to exit.\n");
  while (1) {
    printf("Type in something:\n");
    char buf[1024];
    fgets(buf, 1024, stdin);
    printf("You typed:\n");
    printf(buf);
    printf("\n");
    printf("What happens if you type '%%d' or '%%s' or '%%s%%s%%s%%s'?\n");
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xec7(%rip),%rdi
call   1030 <printf@plt>
lea    0xed2(%rip),%rdi
call   1030 <printf@plt>
lea    -0x410(%rbp),%rdi
mov    0x2e90(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   1040 <fgets@plt>
lea    0xec0(%rip),%rdi
call   1030 <printf@plt>
lea    -0x410(%rbp),%rdi
call   1030 <printf@plt>
lea    0xe92(%rip),%rdi
call   1030 <printf@plt>
lea    0xea8(%rip),%rdi
call   1030 <printf@plt>
jmp    113e <main+0x1e>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x400,%rsp
lea    0xee5(%rip),%rdi
call   1040 <puts@plt>
lea    0xeef(%rip),%r14
mov    0x2e7e(%rip),%r13
mov    %rsp,%rbx
lea    0xef1(%rip),%r15
lea    0xe85(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1040 <puts@plt>
mov    0x0(%r13),%edx
mov    %rbx,%rdi
mov    $0x400,%esi
call   1060 <fgets@plt>
mov    %r15,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r12,%rdi
call   1050 <printf@plt>
jmp    1180 <main+0x40>

LLVM IR (-O0):
@.str = [23 x i8] c"Press Ctrl+C to exit.\0A\00"
@.str.1 = [20 x i8] c"Type in something:\0A\00"
@stdin = global i32 0
@.str.2 = [12 x i8] c"You typed:\0A\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [60 x i8] c"What happens if you type '%%d' or '%%s' or '%%s%%s%%s%%s'?\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1024 x i8]
store i32 0, i32* %1
%3 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %4
4: ; preds = %0, %4
%5 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%7 = load i32, i32* @stdin
%8 = call i32 @fgets(i8* %6, i32 1024, i32 %7)
%9 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%11 = call i32 @printf(i8* %10)
%12 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%13 = call i32 @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.4, i64 0, i64 0))
br label %4
}

LLVM IR (-O2):
@stdin = global i32 0
@.str.4 = [60 x i8] c"What happens if you type '%%d' or '%%s' or '%%s%%s%%s%%s'?\0A\00"
@str = [22 x i8] c"Press Ctrl+C to exit.\00"
@str.5 = [19 x i8] c"Type in something:\00"
@str.6 = [11 x i8] c"You typed:\00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
br label %4
4: ; preds = %0, %4
%5 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.5, i64 0, i64 0))
%6 = load i32, i32* @stdin
%7 = call i32 @fgets(i8* %3, i32 1024, i32 %6)
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.6, i64 0, i64 0))
%9 = call i32 @printf(i8* %3)
%10 = call i32 @putchar(i32 10)
%11 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @.str.4, i64 0, i64 0))
br label %4
}