#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__ islower(int);
scalar_t__ isupper(int);
int encode(int ch, int key) {
  if (islower(ch))
    ch = (ch - 'a' + key) % 26 + 'a';
  else if (isupper(ch))
    ch = (ch - 'A' + key) % 26 + 'A';
  return ch;
}


x86 assembly (clang, -O0):
<encode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <islower@plt>
cmp    $0x0,%rax
je     115c <encode+0x3c>
mov    -0x4(%rbp),%eax
sub    $0x61,%eax
add    -0x8(%rbp),%eax
mov    $0x1a,%ecx
cltd
idiv   %ecx
add    $0x61,%edx
mov    %edx,-0x4(%rbp)
jmp    118a <encode+0x6a>
mov    -0x4(%rbp),%edi
call   1040 <isupper@plt>
cmp    $0x0,%rax
je     1185 <encode+0x65>
mov    -0x4(%rbp),%eax
sub    $0x41,%eax
add    -0x8(%rbp),%eax
mov    $0x1a,%ecx
cltd
idiv   %ecx
add    $0x41,%edx
mov    %edx,-0x4(%rbp)
jmp    118a <encode+0x6a>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<encode>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %edi,%ebx
call   1030 <islower@plt>
test   %rax,%rax
je     1160 <encode+0x40>
lea    (%r14,%rbx,1),%eax
add    $0xffffff9f,%eax
movslq %eax,%rbx
imul   $0x4ec4ec4f,%rbx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x23,%rax
add    %ecx,%eax
lea    (%rax,%rax,4),%ecx
lea    (%rcx,%rcx,4),%ecx
add    %eax,%ecx
sub    %ecx,%ebx
add    $0x61,%ebx
jmp    1197 <encode+0x77>
mov    %ebx,%edi
call   1040 <isupper@plt>
test   %rax,%rax
je     1197 <encode+0x77>
lea    (%r14,%rbx,1),%eax
add    $0xffffffbf,%eax
movslq %eax,%rbx
imul   $0x4ec4ec4f,%rbx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x23,%rax
add    %ecx,%eax
lea    (%rax,%rax,4),%ecx
lea    (%rcx,%rcx,4),%ecx
add    %eax,%ecx
sub    %ecx,%ebx
add    $0x41,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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