#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*/ block_cipher(char *, char *, int);
int /*<<< orphan*/ key_setup(void *, char *);
int decrypt9p(void *key, void *vbuf, int n) {
  char ekey[128], *buf;
  int i, r;
  if (n < 8)
    return 0;
  key_setup(key, ekey);
  buf = vbuf;
  n--;
  r = n % 7;
  n /= 7;
  buf += n * 7;
  if (r)
    block_cipher(ekey, buf - 7 + r, 1);
  for (i = 0; i < n; i++) {
    buf -= 7;
    block_cipher(ekey, buf, 1);
  }
  return 1;
}


x86 assembly (clang, -O0):
<decrypt9p>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpl   $0x8,-0x1c(%rbp)
jge    114c <decrypt9p+0x2c>
movl   $0x0,-0x4(%rbp)
jmp    1238 <decrypt9p+0x118>
mov    -0x10(%rbp),%rdi
lea    -0xa0(%rbp),%rsi
call   1030 <key_setup@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0xa8(%rbp)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
mov    %edx,-0xb0(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
imul   $0x7,-0x1c(%rbp),%ecx
mov    -0xa8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0xa8(%rbp)
cmpl   $0x0,-0xb0(%rbp)
je     11da <decrypt9p+0xba>
lea    -0xa0(%rbp),%rdi
mov    -0xa8(%rbp),%rsi
add    $0xfffffffffffffff9,%rsi
movslq -0xb0(%rbp),%rax
add    %rax,%rsi
mov    $0x1,%edx
call   1040 <block_cipher@plt>
movl   $0x0,-0xac(%rbp)
mov    -0xac(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1231 <decrypt9p+0x111>
mov    -0xa8(%rbp),%rax
add    $0xfffffffffffffff9,%rax
mov    %rax,-0xa8(%rbp)
lea    -0xa0(%rbp),%rdi
mov    -0xa8(%rbp),%rsi
mov    $0x1,%edx
call   1040 <block_cipher@plt>
mov    -0xac(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xac(%rbp)
jmp    11e4 <decrypt9p+0xc4>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decrypt9p>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x88,%rsp
xor    %r15d,%r15d
cmp    $0x8,%edx
jl     11b9 <decrypt9p+0x99>
mov    %edx,%ebx
mov    %rsi,%r14
mov    %rsp,%rsi
call   1030 <key_setup@plt>
add    $0xffffffff,%ebx
imul   $0x24924925,%rbx,%rax
shr    $0x20,%rax
mov    %ebx,%ebp
sub    %eax,%ebp
shr    %ebp
add    %eax,%ebp
shr    $0x2,%ebp
lea    0x0(,%rbp,8),%r15d
sub    %ebp,%r15d
sub    %r15d,%ebx
je     118a <decrypt9p+0x6a>
lea    (%r14,%r15,1),%rax
mov    %ebx,%ecx
lea    (%rax,%rcx,1),%rsi
add    $0xfffffffffffffff9,%rsi
mov    %rsp,%rdi
mov    $0x1,%edx
call   1040 <block_cipher@plt>
lea    (%r15,%r14,1),%rbx
add    $0xfffffffffffffff9,%rbx
mov    %rsp,%r14
mov    $0x1,%r15d
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <block_cipher@plt>
add    $0xfffffffffffffff9,%rbx
add    $0xffffffff,%ebp
jne    11a0 <decrypt9p+0x80>
mov    %r15d,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @decrypt9p(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca [128 x i8]
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%12 = load i32, i32* %7
%13 = icmp slt i32 %12, 8
br i1 %13, label %14, label %15
14: ; preds = %3
store i32 0, i32* %4
br label %56
15: ; preds = %3
%16 = load i8*, i8** %5
%17 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%18 = call i32 @key_setup(i8* %16, i8* %17)
%19 = load i8*, i8** %6
store i8* %19, i8** %9
%20 = load i32, i32* %7
%21 = add nsw i32 %20, -1
store i32 %21, i32* %7
%22 = load i32, i32* %7
%23 = srem i32 %22, 7
store i32 %23, i32* %11
%24 = load i32, i32* %7
%25 = sdiv i32 %24, 7
store i32 %25, i32* %7
%26 = load i32, i32* %7
%27 = mul nsw i32 %26, 7
%28 = load i8*, i8** %9
%29 = sext i32 %27 to i64
%30 = getelementptr inbounds i8, i8* %28, i64 %29
store i8* %30, i8** %9
%31 = load i32, i32* %11
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %41
33: ; preds = %15
%34 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%35 = load i8*, i8** %9
%36 = getelementptr inbounds i8, i8* %35, i64 -7
%37 = load i32, i32* %11
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
%40 = call i32 @block_cipher(i8* %34, i8* %39, i32 1)
br label %41
41: ; preds = %33, %15
store i32 0, i32* %10
br label %42
42: ; preds = %52, %41
%43 = load i32, i32* %10
%44 = load i32, i32* %7
%45 = icmp slt i32 %43, %44
br i1 %45, label %46, label %55
46: ; preds = %42
%47 = load i8*, i8** %9
%48 = getelementptr inbounds i8, i8* %47, i64 -7
store i8* %48, i8** %9
%49 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%50 = load i8*, i8** %9
%51 = call i32 @block_cipher(i8* %49, i8* %50, i32 1)
br label %52
52: ; preds = %46
%53 = load i32, i32* %10
%54 = add nsw i32 %53, 1
store i32 %54, i32* %10
br label %42
55: ; preds = %42
store i32 1, i32* %4
br label %56
56: ; preds = %55, %14
%57 = load i32, i32* %4
ret i32 %57
}

LLVM IR (-O2):
define i32 @decrypt9p(i8* %0, i8* %1, i32 %2) {
%4 = alloca [128 x i8]
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%6 = icmp slt i32 %2, 8
br i1 %6, label %29, label %7
7: ; preds = %3
%8 = call i32 @key_setup(i8* %0, i8* %5)
%9 = add nsw i32 %2, -1
%10 = urem i32 %9, 7
%11 = udiv i32 %9, 7
%12 = mul nuw nsw i32 %11, 7
%13 = zext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %1, i64 %13
%15 = icmp eq i32 %10, 0
br i1 %15, label %21, label %16
16: ; preds = %7
%17 = getelementptr inbounds i8, i8* %14, i64 -7
%18 = zext i32 %10 to i64
%19 = getelementptr inbounds i8, i8* %17, i64 %18
%20 = call i32 @block_cipher(i8* %5, i8* %19, i32 1)
br label %21
21: ; preds = %7, %16
br label %22
22: ; preds = %21, %22
%23 = phi i32 [ %27, %22 ], [ 0, %21 ]
%24 = phi i8* [ %25, %22 ], [ %14, %21 ]
%25 = getelementptr inbounds i8, i8* %24, i64 -7
%26 = call i32 @block_cipher(i8* %5, i8* %25, i32 1)
%27 = add nuw nsw i32 %23, 1
%28 = icmp eq i32 %27, %11
br i1 %28, label %29, label %22
29: ; preds = %22, %3
%30 = phi i32 [ 0, %3 ], [ 1, %22 ]
ret i32 %30
}