#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 unsigned char ssize_t;

/* Variables and functions */
unsigned char find_in_data(unsigned char *, size_t, unsigned char);
int /*<<< orphan*/ printf(char *);
int cipher_shift(unsigned char *data, size_t datalen, unsigned char *shiftdata,
                 size_t shiftlen, unsigned char *alphabet, size_t alphabetlen,
                 unsigned char *out) {
  size_t i;
  for (i = 0; i < datalen; ++i) {
    ssize_t idx = find_in_data(alphabet, alphabetlen, data[i]);
    unsigned int res = idx + shiftdata[i % shiftlen];
    if (idx == -1) {
      printf("Out of bound data, unable to cipher_shift!\n");
      return 1;
    }
    out[i] = alphabet[res % alphabetlen];
  }
  return 0;
}


x86 assembly (clang, -O0):
<cipher_shift>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11f2 <cipher_shift+0xd2>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    -0x40(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
call   1030 <find_in_data@plt>
mov    %al,-0x41(%rbp)
movzbl -0x41(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x20(%rbp),%rcx
mov    -0x40(%rbp),%rax
xor    %edx,%edx
divq   -0x28(%rbp)
mov    -0x4c(%rbp),%eax
movzbl (%rcx,%rdx,1),%ecx
add    %ecx,%eax
mov    %eax,-0x48(%rbp)
movzbl -0x41(%rbp),%eax
cmp    $0xffffffff,%eax
jne    11bc <cipher_shift+0x9c>
lea    0xe55(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11f9 <cipher_shift+0xd9>
mov    -0x30(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x48(%rbp),%eax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x38(%rbp)
mov    -0x58(%rbp),%rax
mov    (%rax,%rdx,1),%dl
mov    0x10(%rbp),%rax
mov    -0x40(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    114c <cipher_shift+0x2c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cipher_shift>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,(%rsp)
test   %rsi,%rsi
je     11a3 <cipher_shift+0x93>
mov    %r9,%rbx
mov    %r8,%r14
mov    %rcx,%r15
mov    %rsi,%r13
mov    %rdi,%rbp
xor    %r12d,%r12d
jmp    1157 <cipher_shift+0x47>
nopl   0x0(%rax,%rax,1)
movzbl (%r14,%rax,1),%eax
mov    0x40(%rsp),%rcx
mov    %al,(%rcx,%r12,1)
add    $0x1,%r12
cmp    %r12,%r13
je     11a3 <cipher_shift+0x93>
movzbl 0x0(%rbp,%r12,1),%edx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <find_in_data@plt>
mov    %eax,%ecx
mov    %r12,%rax
or     %r15,%rax
shr    $0x20,%rax
je     1180 <cipher_shift+0x70>
mov    %r12,%rax
xor    %edx,%edx
div    %r15
jmp    1188 <cipher_shift+0x78>
mov    %r12d,%eax
xor    %edx,%edx
div    %r15d
movzbl %cl,%ecx
mov    (%rsp),%rax
movzbl (%rax,%rdx,1),%eax
add    %rcx,%rax
cmp    %rbx,%rax
jb     1140 <cipher_shift+0x30>
xor    %edx,%edx
div    %ebx
mov    %edx,%eax
jmp    1140 <cipher_shift+0x30>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [44 x i8] c"Out of bound data, unable to cipher_shift!\0A\00"
define i32 @cipher_shift(i8* %0, i64 %1, i8* %2, i64 %3, i8* %4, i64 %5, i8* %6) {
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i8*
%14 = alloca i64
%15 = alloca i8*
%16 = alloca i64
%17 = alloca i8
%18 = alloca i32
store i8* %0, i8** %9
store i64 %1, i64* %10
store i8* %2, i8** %11
store i64 %3, i64* %12
store i8* %4, i8** %13
store i64 %5, i64* %14
store i8* %6, i8** %15
store i64 0, i64* %16
br label %19
19: ; preds = %57, %7
%20 = load i64, i64* %16
%21 = load i64, i64* %10
%22 = icmp ult i64 %20, %21
br i1 %22, label %23, label %60
23: ; preds = %19
%24 = load i8*, i8** %13
%25 = load i64, i64* %14
%26 = load i8*, i8** %9
%27 = load i64, i64* %16
%28 = getelementptr inbounds i8, i8* %26, i64 %27
%29 = load i8, i8* %28
%30 = call zeroext i8 @find_in_data(i8* %24, i64 %25, i8 zeroext %29)
store i8 %30, i8* %17
%31 = load i8, i8* %17
%32 = zext i8 %31 to i32
%33 = load i8*, i8** %11
%34 = load i64, i64* %16
%35 = load i64, i64* %12
%36 = urem i64 %34, %35
%37 = getelementptr inbounds i8, i8* %33, i64 %36
%38 = load i8, i8* %37
%39 = zext i8 %38 to i32
%40 = add nsw i32 %32, %39
store i32 %40, i32* %18
%41 = load i8, i8* %17
%42 = zext i8 %41 to i32
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %46
44: ; preds = %23
%45 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %8
br label %61
46: ; preds = %23
%47 = load i8*, i8** %13
%48 = load i32, i32* %18
%49 = zext i32 %48 to i64
%50 = load i64, i64* %14
%51 = urem i64 %49, %50
%52 = getelementptr inbounds i8, i8* %47, i64 %51
%53 = load i8, i8* %52
%54 = load i8*, i8** %15
%55 = load i64, i64* %16
%56 = getelementptr inbounds i8, i8* %54, i64 %55
store i8 %53, i8* %56
br label %57
57: ; preds = %46
%58 = load i64, i64* %16
%59 = add i64 %58, 1
store i64 %59, i64* %16
br label %19
60: ; preds = %19
store i32 0, i32* %8
br label %61
61: ; preds = %60, %44
%62 = load i32, i32* %8
ret i32 %62
}

LLVM IR (-O2):
define i32 @cipher_shift(i8* nocapture %0, i64 %1, i8* nocapture %2, i64 %3, i8* %4, i64 %5, i8* nocapture writeonly %6) {
%8 = icmp eq i64 %1, 0
br i1 %8, label %26, label %9
9: ; preds = %7, %9
%10 = phi i64 [ %24, %9 ], [ 0, %7 ]
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = load i8, i8* %11
%13 = tail call zeroext i8 @find_in_data(i8* %4, i64 %5, i8 zeroext %12)
%14 = zext i8 %13 to i64
%15 = urem i64 %10, %3
%16 = getelementptr inbounds i8, i8* %2, i64 %15
%17 = load i8, i8* %16
%18 = zext i8 %17 to i64
%19 = add nuw nsw i64 %18, %14
%20 = urem i64 %19, %5
%21 = getelementptr inbounds i8, i8* %4, i64 %20
%22 = load i8, i8* %21
%23 = getelementptr inbounds i8, i8* %6, i64 %10
store i8 %22, i8* %23
%24 = add nuw i64 %10, 1
%25 = icmp eq i64 %24, %1
br i1 %25, label %26, label %9
26: ; preds = %9, %7
ret i32 0
}