#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 */
char EOF;
int /*<<< orphan*/ free(char *);
char getchar();
char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
char *realloc(char *, int);
char *rot13(char *);
int main(int argc, char **argv) {
  int ignoreNewline = 0;
  int size = 50;
  char *input = malloc(size * sizeof(char));
  int pos = 0;
  printf("Enter the string you wish to ROT13, ending with a newline\n");
  while ((input[pos] = getchar()) != EOF) {
    if (input[pos] == '\n' && ignoreNewline == 0)
      break;
    pos++;
    if (pos >= size) {
      size += 50;
      input = realloc(input, size);
    }
  }
  if (ignoreNewline && pos <= size)
    input[pos + 1] = '\0';
  else
    input[pos] = '\0';
  char *encoded = rot13(input);
  printf("%s\n", encoded);
  free(input);
  free(encoded);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x32,-0x18(%rbp)
movslq -0x18(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    -0x20(%rbp),%rcx
movslq -0x24(%rbp),%rdx
mov    %al,(%rcx,%rdx,1)
movsbl %al,%eax
mov    0x2e20(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     122a <main+0xca>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    11f7 <main+0x97>
cmpl   $0x0,-0x14(%rbp)
jne    11f7 <main+0x97>
jmp    122a <main+0xca>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x18(%rbp),%eax
jl     1225 <main+0xc5>
mov    -0x18(%rbp),%eax
add    $0x32,%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1080 <realloc@plt>
mov    %rax,-0x20(%rbp)
jmp    11ac <main+0x4c>
cmpl   $0x0,-0x14(%rbp)
je     1256 <main+0xf6>
mov    -0x24(%rbp),%eax
cmp    -0x18(%rbp),%eax
jg     1256 <main+0xf6>
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1262 <main+0x102>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
call   1040 <rot13@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rsi
lea    0xdc1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x32,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
lea    0xe85(%rip),%rdi
call   1040 <puts@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <getchar@plt>
mov    %al,(%r14)
cmp    $0xa,%al
je     11df <main+0x7f>
mov    0x2e51(%rip),%r15
cmp    (%r15),%al
je     11df <main+0x7f>
mov    $0x32,%ebp
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
cmp    %ebx,%ebp
jg     11c4 <main+0x64>
add    $0x32,%ebp
mov    %r14,%rdi
mov    %ebp,%esi
call   1080 <realloc@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1060 <getchar@plt>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    $0xa,%al
je     11dc <main+0x7c>
cmp    (%r15),%al
jne    11b0 <main+0x50>
add    $0xffffffff,%ebx
movb   $0x0,(%r14,%rbx,1)
mov    %r14,%rdi
call   1050 <rot13@plt>
mov    %rax,%rbp
mov    %rax,%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [59 x i8] c"Enter the string you wish to ROT13, ending with a newline\0A\00"
@EOF = global i8 0
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 50, i32* %7
%11 = load i32, i32* %7
%12 = sext i32 %11 to i64
%13 = mul i64 %12, 1
%14 = trunc i64 %13 to i32
%15 = call i8* @malloc(i32 %14)
store i8* %15, i8** %8
store i32 0, i32* %9
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %51, %2
%18 = call signext i8 (...) @getchar()
%19 = load i8*, i8** %8
%20 = load i32, i32* %9
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
store i8 %18, i8* %22
%23 = sext i8 %18 to i32
%24 = load i8, i8* @EOF
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %23, %25
br i1 %26, label %27, label %52
27: ; preds = %17
%28 = load i8*, i8** %8
%29 = load i32, i32* %9
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 10
br i1 %34, label %35, label %39
35: ; preds = %27
%36 = load i32, i32* %6
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %35
br label %52
39: ; preds = %35, %27
%40 = load i32, i32* %9
%41 = add nsw i32 %40, 1
store i32 %41, i32* %9
%42 = load i32, i32* %9
%43 = load i32, i32* %7
%44 = icmp sge i32 %42, %43
br i1 %44, label %45, label %51
45: ; preds = %39
%46 = load i32, i32* %7
%47 = add nsw i32 %46, 50
store i32 %47, i32* %7
%48 = load i8*, i8** %8
%49 = load i32, i32* %7
%50 = call i8* @realloc(i8* %48, i32 %49)
store i8* %50, i8** %8
br label %51
51: ; preds = %45, %39
br label %17
52: ; preds = %38, %17
%53 = load i32, i32* %6
%54 = icmp ne i32 %53, 0
br i1 %54, label %55, label %65
55: ; preds = %52
%56 = load i32, i32* %9
%57 = load i32, i32* %7
%58 = icmp sle i32 %56, %57
br i1 %58, label %59, label %65
59: ; preds = %55
%60 = load i8*, i8** %8
%61 = load i32, i32* %9
%62 = add nsw i32 %61, 1
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8, i8* %60, i64 %63
store i8 0, i8* %64
br label %70
65: ; preds = %55, %52
%66 = load i8*, i8** %8
%67 = load i32, i32* %9
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8, i8* %66, i64 %68
store i8 0, i8* %69
br label %70
70: ; preds = %65, %59
%71 = load i8*, i8** %8
%72 = call i8* @rot13(i8* %71)
store i8* %72, i8** %10
%73 = load i8*, i8** %10
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %73)
%75 = load i8*, i8** %8
%76 = call i32 @free(i8* %75)
%77 = load i8*, i8** %10
%78 = call i32 @free(i8* %77)
ret i32 0
}

LLVM IR (-O2):
@EOF = global i8 0
@str = [58 x i8] c"Enter the string you wish to ROT13, ending with a newline\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call dereferenceable_or_null(50) i8* @malloc(i32 50)
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @str, i64 0, i64 0))
%5 = tail call signext i8 (...) @getchar()
store i8 %5, i8* %3
%6 = load i8, i8* @EOF
%7 = icmp eq i8 %5, %6
%8 = icmp eq i8 %5, 10
%9 = or i1 %8, %7
br i1 %9, label %31, label %10
10: ; preds = %2, %20
%11 = phi i64 [ %14, %20 ], [ 0, %2 ]
%12 = phi i32 [ %22, %20 ], [ 50, %2 ]
%13 = phi i8* [ %21, %20 ], [ %3, %2 ]
%14 = add nuw i64 %11, 1
%15 = trunc i64 %14 to i32
%16 = icmp sgt i32 %12, %15
br i1 %16, label %20, label %17
17: ; preds = %10
%18 = add nsw i32 %12, 50
%19 = tail call i8* @realloc(i8* %13, i32 %18)
br label %20
20: ; preds = %17, %10
%21 = phi i8* [ %19, %17 ], [ %13, %10 ]
%22 = phi i32 [ %18, %17 ], [ %12, %10 ]
%23 = tail call signext i8 (...) @getchar()
%24 = getelementptr inbounds i8, i8* %21, i64 %14
store i8 %23, i8* %24
%25 = load i8, i8* @EOF
%26 = icmp eq i8 %23, %25
%27 = icmp eq i8 %23, 10
%28 = or i1 %27, %26
br i1 %28, label %29, label %10
29: ; preds = %20
%30 = and i64 %14, 4294967295
br label %31
31: ; preds = %29, %2
%32 = phi i64 [ 0, %2 ], [ %30, %29 ]
%33 = phi i8* [ %3, %2 ], [ %21, %29 ]
%34 = getelementptr inbounds i8, i8* %33, i64 %32
store i8 0, i8* %34
%35 = tail call i8* @rot13(i8* %33)
%36 = tail call i32 @puts(i8* dereferenceable(1) %35)
%37 = tail call i32 @free(i8* %33)
%38 = tail call i32 @free(i8* %35)
ret i32 0
}