#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*/ alphatonum(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ isalpha(char);
char *malloc(int);
int /*<<< orphan*/ numtoalpha(char *);
int /*<<< orphan*/ stderr;
int strlen(char *);
char *caesar(char *input, int shift) {
  char *output = NULL;
  int input_len = strlen(input);
  int i;
  if (!(output = malloc(input_len))) {
    fprintf(stderr, "Malloc error!");
    exit(2);
  }
  for (i = 0; i < input_len && isalpha(input[i]); i++) {
    alphatonum(&input[i]);
    output[i] = input[i] + shift;
    if (output[i] >= 26)
      output[i] %= 26;
    output[i] += 'A';
    numtoalpha(&input[i]);
  }
  return output;
}


x86 assembly (clang, -O0):
<caesar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11c8 <caesar+0x58>
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
lea    0xe47(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%ecx
xor    %eax,%eax
cmp    -0x1c(%rbp),%ecx
mov    %al,-0x21(%rbp)
jge    11fb <caesar+0x8b>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1060 <isalpha@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    120b <caesar+0x9b>
jmp    129b <caesar+0x12b>
mov    -0x8(%rbp),%rdi
movslq -0x20(%rbp),%rax
add    %rax,%rdi
call   1070 <alphatonum@plt>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
add    -0xc(%rbp),%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x1a,%eax
jl     126b <caesar+0xfb>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    $0x1a,%esi
cltd
idiv   %esi
mov    -0x30(%rbp),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
add    $0x41,%edx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
movslq -0x20(%rbp),%rax
add    %rax,%rdi
call   1090 <numtoalpha@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11cf <caesar+0x5f>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<caesar>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%r13
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     1215 <caesar+0xa5>
mov    %rax,%r15
test   %ebp,%ebp
jle    1203 <caesar+0x93>
mov    %ebp,%r12d
xor    %ebx,%ebx
jmp    11c7 <caesar+0x57>
cs nopw 0x0(%rax,%rax,1)
add    $0x41,%al
mov    %al,(%r15,%rbx,1)
mov    %rbp,%rdi
call   1090 <numtoalpha@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
je     1203 <caesar+0x93>
movsbl 0x0(%r13,%rbx,1),%edi
call   1060 <isalpha@plt>
test   %rax,%rax
je     1203 <caesar+0x93>
lea    (%rbx,%r13,1),%rbp
mov    %rbp,%rdi
call   1070 <alphatonum@plt>
movzbl 0x0(%rbp),%eax
add    %r14b,%al
cmp    $0x1a,%al
jl     11b0 <caesar+0x40>
movzbl %al,%ecx
imul   $0x4f,%ecx,%ecx
shr    $0xb,%ecx
lea    (%rcx,%rcx,4),%edx
lea    (%rdx,%rdx,4),%edx
add    %ecx,%edx
sub    %dl,%al
jmp    11b0 <caesar+0x40>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
lea    0xddb(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [14 x i8] c"Malloc error!\00"
define i8* @caesar(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i8* null, i8** %5
%8 = load i8*, i8** %3
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = call i8* @malloc(i32 %10)
store i8* %11, i8** %5
%12 = icmp ne i8* %11, null
br i1 %12, label %17, label %13
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 2)
unreachable
17: ; preds = %2
store i32 0, i32* %7
br label %18
18: ; preds = %81, %17
%19 = load i32, i32* %7
%20 = load i32, i32* %6
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %30
22: ; preds = %18
%23 = load i8*, i8** %3
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8, i8* %26
%28 = call i64 @isalpha(i8 signext %27)
%29 = icmp ne i64 %28, 0
br label %30
30: ; preds = %22, %18
%31 = phi i1 [ false, %18 ], [ %29, %22 ]
br i1 %31, label %32, label %84
32: ; preds = %30
%33 = load i8*, i8** %3
%34 = load i32, i32* %7
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = call i32 @alphatonum(i8* %36)
%38 = load i8*, i8** %3
%39 = load i32, i32* %7
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = load i32, i32* %4
%45 = add nsw i32 %43, %44
%46 = trunc i32 %45 to i8
%47 = load i8*, i8** %5
%48 = load i32, i32* %7
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %47, i64 %49
store i8 %46, i8* %50
%51 = load i8*, i8** %5
%52 = load i32, i32* %7
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
%55 = load i8, i8* %54
%56 = sext i8 %55 to i32
%57 = icmp sge i32 %56, 26
br i1 %57, label %58, label %67
58: ; preds = %32
%59 = load i8*, i8** %5
%60 = load i32, i32* %7
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8, i8* %59, i64 %61
%63 = load i8, i8* %62
%64 = sext i8 %63 to i32
%65 = srem i32 %64, 26
%66 = trunc i32 %65 to i8
store i8 %66, i8* %62
br label %67
67: ; preds = %58, %32
%68 = load i8*, i8** %5
%69 = load i32, i32* %7
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i8, i8* %68, i64 %70
%72 = load i8, i8* %71
%73 = sext i8 %72 to i32
%74 = add nsw i32 %73, 65
%75 = trunc i32 %74 to i8
store i8 %75, i8* %71
%76 = load i8*, i8** %3
%77 = load i32, i32* %7
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds i8, i8* %76, i64 %78
%80 = call i32 @numtoalpha(i8* %79)
br label %81
81: ; preds = %67
%82 = load i32, i32* %7
%83 = add nsw i32 %82, 1
store i32 %83, i32* %7
br label %18
84: ; preds = %30
%85 = load i8*, i8** %5
ret i8* %85
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [14 x i8] c"Malloc error!\00"
define noalias i8* @caesar(i8* %0, i32 %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = tail call i8* @malloc(i32 %3)
%5 = icmp eq i8* %4, null
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = icmp sgt i32 %3, 0
br i1 %7, label %8, label %33
8: ; preds = %6
%9 = trunc i32 %1 to i8
%10 = zext i32 %3 to i64
br label %15
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%14 = tail call i32 @exit(i32 2)
unreachable
15: ; preds = %8, %21
%16 = phi i64 [ 0, %8 ], [ %31, %21 ]
%17 = getelementptr inbounds i8, i8* %0, i64 %16
%18 = load i8, i8* %17
%19 = tail call i64 @isalpha(i8 signext %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %33, label %21
21: ; preds = %15
%22 = tail call i32 @alphatonum(i8* %17)
%23 = load i8, i8* %17
%24 = add i8 %23, %9
%25 = getelementptr inbounds i8, i8* %4, i64 %16
%26 = icmp sgt i8 %24, 25
%27 = urem i8 %24, 26
%28 = select i1 %26, i8 %27, i8 %24
%29 = add nsw i8 %28, 65
store i8 %29, i8* %25
%30 = tail call i32 @numtoalpha(i8* %17)
%31 = add nuw nsw i64 %16, 1
%32 = icmp eq i64 %31, %10
br i1 %32, label %33, label %15
33: ; preds = %15, %21, %6
ret i8* %4
}