#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 */
scalar_t__ isalpha(char);
scalar_t__ isupper(char);
char rotate(char c, int key) {
  int base = 0;
  if (isalpha(c)) {
    if (isupper(c)) {
      base = 65;
    } else {
      base = 97;
    }
    c = (((c - base) + key) % 26) + base;
  }
  return c;
}


x86 assembly (clang, -O0):
<rotate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movsbl -0x1(%rbp),%edi
call   1030 <isalpha@plt>
cmp    $0x0,%rax
je     118b <rotate+0x6b>
movsbl -0x1(%rbp),%edi
call   1040 <isupper@plt>
cmp    $0x0,%rax
je     116a <rotate+0x4a>
movl   $0x41,-0xc(%rbp)
jmp    1171 <rotate+0x51>
movl   $0x61,-0xc(%rbp)
movsbl -0x1(%rbp),%eax
sub    -0xc(%rbp),%eax
add    -0x8(%rbp),%eax
mov    $0x1a,%ecx
cltd
idiv   %ecx
add    -0xc(%rbp),%edx
mov    %dl,%al
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rotate>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %edi,%ebx
call   1030 <isalpha@plt>
test   %rax,%rax
je     1180 <rotate+0x60>
movsbl %bl,%ebx
mov    %ebx,%edi
call   1040 <isupper@plt>
xor    %ecx,%ecx
xor    %edx,%edx
test   %rax,%rax
sete   %cl
setne  %dl
shl    $0x5,%edx
shl    $0x5,%ecx
add    %ebx,%r14d
lea    (%rdx,%r14,1),%eax
add    $0xffffff9f,%eax
movslq %eax,%rbx
imul   $0x4ec4ec4f,%rbx,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x23,%rax
add    %edx,%eax
lea    (%rax,%rax,4),%edx
lea    (%rdx,%rdx,4),%edx
add    %eax,%edx
sub    %edx,%ebx
add    %ecx,%ebx
add    $0x41,%bl
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define signext i8 @rotate(i8 signext %0, i32 %1) {
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32
store i8 %0, i8* %3
store i32 %1, i32* %4
store i32 0, i32* %5
%6 = load i8, i8* %3
%7 = call i64 @isalpha(i8 signext %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %26
9: ; preds = %2
%10 = load i8, i8* %3
%11 = call i64 @isupper(i8 signext %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %9
store i32 65, i32* %5
br label %15
14: ; preds = %9
store i32 97, i32* %5
br label %15
15: ; preds = %14, %13
%16 = load i8, i8* %3
%17 = sext i8 %16 to i32
%18 = load i32, i32* %5
%19 = sub nsw i32 %17, %18
%20 = load i32, i32* %4
%21 = add nsw i32 %19, %20
%22 = srem i32 %21, 26
%23 = load i32, i32* %5
%24 = add nsw i32 %22, %23
%25 = trunc i32 %24 to i8
store i8 %25, i8* %3
br label %26
26: ; preds = %15, %2
%27 = load i8, i8* %3
ret i8 %27
}

LLVM IR (-O2):
define signext i8 @rotate(i8 signext %0, i32 %1) {
%3 = tail call i64 @isalpha(i8 signext %0)
%4 = icmp eq i64 %3, 0
br i1 %4, label %16, label %5
5: ; preds = %2
%6 = tail call i64 @isupper(i8 signext %0)
%7 = icmp eq i64 %6, 0
%8 = select i1 %7, i32 -97, i32 -65
%9 = select i1 %7, i32 97, i32 65
%10 = sext i8 %0 to i32
%11 = add i32 %10, %1
%12 = add i32 %11, %8
%13 = srem i32 %12, 26
%14 = add nsw i32 %13, %9
%15 = trunc i32 %14 to i8
br label %16
16: ; preds = %5, %2
%17 = phi i8 [ %15, %5 ], [ %0, %2 ]
ret i8 %17
}