#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*/ free(char *);
char *malloc(scalar_t__);
int /*<<< orphan*/ printf(char *, char *, char *, char *);
int /*<<< orphan*/ railfence_decipher(int, char *, char *);
int /*<<< orphan*/ railfence_encipher(int, char *, char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ system(char *);
int main(int argc, char *argv[]) {
  char *plaintext = "defendtheeastwallofthecastle";
  char *ciphertext = malloc(strlen(plaintext) + 1);
  char *result = malloc(strlen(plaintext) + 1);
  railfence_encipher(3, plaintext, ciphertext);
  railfence_decipher(3, ciphertext, result);
  printf("-->original:   %s\n-->ciphertext: %s\n-->plaintext:  %s\n", plaintext,
         ciphertext, result);
  free(ciphertext);
  free(result);
  system("PAUSE");
  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)
lea    0xe73(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1090 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1090 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    $0x3,%edi
call   1080 <railfence_encipher@plt>
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    $0x3,%edi
call   1070 <railfence_decipher@plt>
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
lea    0xe23(%rip),%rdi
call   1060 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
lea    0xe3c(%rip),%rdi
call   1050 <system@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    $0x1d,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    $0x1d,%edi
call   1080 <malloc@plt>
mov    %rax,%r14
lea    0xe7a(%rip),%r15
mov    $0x3,%edi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1070 <railfence_encipher@plt>
mov    $0x3,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1060 <railfence_decipher@plt>
lea    0xe70(%rip),%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
lea    0xe82(%rip),%rdi
call   1040 <system@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [29 x i8] c"defendtheeastwallofthecastle\00"
@.str.1 = [55 x i8] c"-->original: %s\0A-->ciphertext: %s\0A-->plaintext: %s\0A\00"
@.str.2 = [6 x i8] c"PAUSE\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8** %6
%9 = load i8*, i8** %6
%10 = call i64 @strlen(i8* %9)
%11 = add nsw i64 %10, 1
%12 = call i8* @malloc(i64 %11)
store i8* %12, i8** %7
%13 = load i8*, i8** %6
%14 = call i64 @strlen(i8* %13)
%15 = add nsw i64 %14, 1
%16 = call i8* @malloc(i64 %15)
store i8* %16, i8** %8
%17 = load i8*, i8** %6
%18 = load i8*, i8** %7
%19 = call i32 @railfence_encipher(i32 3, i8* %17, i8* %18)
%20 = load i8*, i8** %7
%21 = load i8*, i8** %8
%22 = call i32 @railfence_decipher(i32 3, i8* %20, i8* %21)
%23 = load i8*, i8** %6
%24 = load i8*, i8** %7
%25 = load i8*, i8** %8
%26 = call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0), i8* %23, i8* %24, i8* %25)
%27 = load i8*, i8** %7
%28 = call i32 @free(i8* %27)
%29 = load i8*, i8** %8
%30 = call i32 @free(i8* %29)
%31 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [29 x i8] c"defendtheeastwallofthecastle\00"
@.str.1 = [55 x i8] c"-->original: %s\0A-->ciphertext: %s\0A-->plaintext: %s\0A\00"
@.str.2 = [6 x i8] c"PAUSE\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call dereferenceable_or_null(29) i8* @malloc(i64 29)
%4 = tail call dereferenceable_or_null(29) i8* @malloc(i64 29)
%5 = tail call i32 @railfence_encipher(i32 3, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %3)
%6 = tail call i32 @railfence_decipher(i32 3, i8* %3, i8* %4)
%7 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %3, i8* %4)
%8 = tail call i32 @free(i8* %3)
%9 = tail call i32 @free(i8* %4)
%10 = tail call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}