#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 /*<<< orphan*/ escape(char *, char *);
int getchar();
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  int ret = 0;
  int c = 0, i = 0;
  char s[30 + 1], t[30 + 1];
  printf("\n Give the string that you have to copy that doesn't have more then "
         "%d chars, also \n",
         30);
  while ((c = getchar()) != EOF) {
    if (i >= 30) {
      printf("\n You give more data that I can process! \n");
      break;
    }
    t[i] = c;
    i++;
  }
  t[i + 1] = '\0';
  escape(s, t);
  printf("The string you typed is %s", s);
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xea5(%rip),%rdi
mov    $0x1e,%esi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e70(%rip),%rcx
cmp    (%rcx),%eax
je     11b8 <main+0x88>
cmpl   $0x1e,-0x10(%rbp)
jl     119d <main+0x6d>
lea    0xec4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b8 <main+0x88>
mov    -0xc(%rbp),%eax
mov    %al,%cl
movslq -0x10(%rbp),%rax
mov    %cl,-0x50(%rbp,%rax,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1167 <main+0x37>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
cltq
movb   $0x0,-0x50(%rbp,%rax,1)
lea    -0x30(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1050 <escape@plt>
lea    -0x30(%rbp),%rsi
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x48,%rsp
lea    0xeb2(%rip),%rdi
mov    $0x1e,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
mov    0x2e80(%rip),%r14
mov    $0x1,%ebx
cmp    (%r14),%eax
je     11ad <main+0x6d>
mov    $0x1,%ebx
nopw   0x0(%rax,%rax,1)
cmp    $0x1f,%rbx
je     119c <main+0x5c>
mov    %al,-0x1(%rsp,%rbx,1)
xor    %eax,%eax
call   1050 <getchar@plt>
add    $0x1,%rbx
cmp    (%r14),%eax
jne    1180 <main+0x40>
jmp    11ad <main+0x6d>
lea    0xecd(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1f,%ebx
movb   $0x0,(%rsp,%rbx,1)
lea    0x20(%rsp),%rbx
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1060 <escape@plt>
lea    0xe8d(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [85 x i8] c"\0A Give the string that you have to copy that doesn't have more then %d chars, also \0A\00"
@EOF = global i32 0
@.str.1 = [43 x i8] c"\0A You give more data that I can process! \0A\00"
@.str.2 = [27 x i8] c"The string you typed is %s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [31 x i8]
%6 = alloca [31 x i8]
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str, i64 0, i64 0), i32 30)
br label %8
8: ; preds = %17, %0
%9 = call i32 (...) @getchar()
store i32 %9, i32* %3
%10 = load i32, i32* @EOF
%11 = icmp ne i32 %9, %10
br i1 %11, label %12, label %25
12: ; preds = %8
%13 = load i32, i32* %4
%14 = icmp sge i32 %13, 30
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
br label %25
17: ; preds = %12
%18 = load i32, i32* %3
%19 = trunc i32 %18 to i8
%20 = load i32, i32* %4
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [31 x i8], [31 x i8]* %6, i64 0, i64 %21
store i8 %19, i8* %22
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 1
store i32 %24, i32* %4
br label %8
25: ; preds = %15, %8
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [31 x i8], [31 x i8]* %6, i64 0, i64 %28
store i8 0, i8* %29
%30 = getelementptr inbounds [31 x i8], [31 x i8]* %5, i64 0, i64 0
%31 = getelementptr inbounds [31 x i8], [31 x i8]* %6, i64 0, i64 0
%32 = call i32 @escape(i8* %30, i8* %31)
%33 = getelementptr inbounds [31 x i8], [31 x i8]* %5, i64 0, i64 0
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %33)
%35 = load i32, i32* %2
ret i32 %35
}

LLVM IR (-O2):
@.str = [85 x i8] c"\0A Give the string that you have to copy that doesn't have more then %d chars, also \0A\00"
@EOF = global i32 0
@.str.2 = [27 x i8] c"The string you typed is %s\00"
@str = [42 x i8] c"\0A You give more data that I can process! \00"
define i32 @main() {
%1 = alloca [31 x i8]
%2 = alloca [31 x i8]
%3 = getelementptr inbounds [31 x i8], [31 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [31 x i8], [31 x i8]* %2, i64 0, i64 0
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([85 x i8], [85 x i8]* @.str, i64 0, i64 0), i32 30)
%6 = tail call i32 (...) @getchar()
%7 = load i32, i32* @EOF
%8 = icmp eq i32 %6, %7
br i1 %8, label %25, label %9
9: ; preds = %0, %15
%10 = phi i64 [ %18, %15 ], [ 0, %0 ]
%11 = phi i32 [ %19, %15 ], [ %6, %0 ]
%12 = icmp eq i64 %10, 30
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str, i64 0, i64 0))
br label %25
15: ; preds = %9
%16 = trunc i32 %11 to i8
%17 = getelementptr inbounds [31 x i8], [31 x i8]* %2, i64 0, i64 %10
store i8 %16, i8* %17
%18 = add nuw nsw i64 %10, 1
%19 = tail call i32 (...) @getchar()
%20 = load i32, i32* @EOF
%21 = icmp eq i32 %19, %20
br i1 %21, label %22, label %9
22: ; preds = %15
%23 = add nuw i64 %10, 2
%24 = and i64 %23, 4294967295
br label %25
25: ; preds = %22, %0, %13
%26 = phi i64 [ 31, %13 ], [ 1, %0 ], [ %24, %22 ]
%27 = getelementptr inbounds [31 x i8], [31 x i8]* %2, i64 0, i64 %26
store i8 0, i8* %27
%28 = call i32 @escape(i8* %3, i8* %4)
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %3)
ret i32 0
}