#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 */
typedef scalar_t__ ssize_t;

/* Variables and functions */
int EXIT_SUCCESS;
char *caesar_decode(char *, scalar_t__, int);
char *caesar_encode(char *, scalar_t__, int);
int /*<<< orphan*/ free(char *);
scalar_t__ getline(char **, size_t *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ stdin;
int main(int argc, char *argv[]) {
  int shift;
  size_t len;
  char *s = NULL;
  printf("Enter message to encode: ");
  ssize_t n = getline(&s, &len, stdin);
  if (n < 0) {
    return EXIT_SUCCESS;
  }
  printf("Enter shift amount: ");
  scanf("%d", &shift);
  char *encoded = caesar_encode(s, n, shift);
  printf("Encoded: %s", encoded);
  char *decoded = caesar_decode(encoded, n, shift);
  printf("Decoded: %s", decoded);
  free(s);
  free(encoded);
  free(decoded);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e55(%rip),%rax
mov    (%rax),%edx
lea    -0x28(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1080 <getline@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jge    11c2 <main+0x62>
mov    0x2e20(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1253 <main+0xf3>
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe58(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1070 <scanf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <caesar_encode@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rsi
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1060 <caesar_decode@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rsi
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    0x2d8a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movq   $0x0,0x8(%rsp)
lea    0xe89(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e63(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1080 <getline@plt>
test   %rax,%rax
js     1223 <main+0xc3>
mov    %rax,%rbx
lea    0xe71(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe78(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1070 <scanf@plt>
mov    0x8(%rsp),%rdi
mov    0x4(%rsp),%edx
mov    %rbx,%rsi
call   1050 <caesar_encode@plt>
mov    %rax,%r14
lea    0xe56(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%rsp),%edx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <caesar_decode@plt>
mov    %rax,%rbx
lea    0xe3f(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x2dae(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [26 x i8] c"Enter message to encode: \00"
@stdin = global i32 0
@EXIT_SUCCESS = global i32 0
@.str.1 = [21 x i8] c"Enter shift amount: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [12 x i8] c"Encoded: %s\00"
@.str.4 = [12 x i8] c"Decoded: %s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %8
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @stdin
%14 = call i64 @getline(i8** %8, i64* %7, i32 %13)
store i64 %14, i64* %9
%15 = load i64, i64* %9
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = load i32, i32* @EXIT_SUCCESS
store i32 %18, i32* %3
br label %41
19: ; preds = %2
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %6)
%22 = load i8*, i8** %8
%23 = load i64, i64* %9
%24 = load i32, i32* %6
%25 = call i8* @caesar_encode(i8* %22, i64 %23, i32 %24)
store i8* %25, i8** %10
%26 = load i8*, i8** %10
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %26)
%28 = load i8*, i8** %10
%29 = load i64, i64* %9
%30 = load i32, i32* %6
%31 = call i8* @caesar_decode(i8* %28, i64 %29, i32 %30)
store i8* %31, i8** %11
%32 = load i8*, i8** %11
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* %32)
%34 = load i8*, i8** %8
%35 = call i32 @free(i8* %34)
%36 = load i8*, i8** %10
%37 = call i32 @free(i8* %36)
%38 = load i8*, i8** %11
%39 = call i32 @free(i8* %38)
%40 = load i32, i32* @EXIT_SUCCESS
store i32 %40, i32* %3
br label %41
41: ; preds = %19, %17
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
@.str = [26 x i8] c"Enter message to encode: \00"
@stdin = global i32 0
@EXIT_SUCCESS = global i32 0
@.str.1 = [21 x i8] c"Enter shift amount: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [12 x i8] c"Encoded: %s\00"
@.str.4 = [12 x i8] c"Decoded: %s\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i64
%5 = alloca i8*
%6 = bitcast i32* %3 to i8*
%7 = bitcast i64* %4 to i8*
%8 = bitcast i8** %5 to i8*
store i8* null, i8** %5
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @stdin
%11 = call i64 @getline(i8** %5, i64* %4, i32 %10)
%12 = icmp slt i64 %11, 0
br i1 %12, label %27, label %13
13: ; preds = %2
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%16 = load i8*, i8** %5
%17 = load i32, i32* %3
%18 = call i8* @caesar_encode(i8* %16, i64 %11, i32 %17)
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %18)
%20 = load i32, i32* %3
%21 = call i8* @caesar_decode(i8* %18, i64 %11, i32 %20)
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* %21)
%23 = load i8*, i8** %5
%24 = call i32 @free(i8* %23)
%25 = call i32 @free(i8* %18)
%26 = call i32 @free(i8* %21)
br label %27
27: ; preds = %2, %13
%28 = load i32, i32* @EXIT_SUCCESS
ret i32 %28
}