#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 /*<<< orphan*/);
int /*<<< orphan*/ key_setup(void *, char *);
int encrypt9p(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;
  for (i = 0; i < n; i++) {
    block_cipher(ekey, buf, 0);
    buf += 7;
  }
  if (r)
    block_cipher(ekey, buf - 7 + r, 0);
  return 1;
}


x86 assembly (clang, -O0):
<encrypt9p>:
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 <encrypt9p+0x2c>
movl   $0x0,-0x4(%rbp)
jmp    121a <encrypt9p+0xfa>
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)
movl   $0x0,-0xac(%rbp)
mov    -0xac(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11e3 <encrypt9p+0xc3>
lea    -0xa0(%rbp),%rdi
mov    -0xa8(%rbp),%rsi
xor    %edx,%edx
call   1040 <block_cipher@plt>
mov    -0xa8(%rbp),%rax
add    $0x7,%rax
mov    %rax,-0xa8(%rbp)
mov    -0xac(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xac(%rbp)
jmp    1199 <encrypt9p+0x79>
cmpl   $0x0,-0xb0(%rbp)
je     1213 <encrypt9p+0xf3>
lea    -0xa0(%rbp),%rdi
mov    -0xa8(%rbp),%rsi
add    $0xfffffffffffffff9,%rsi
movslq -0xb0(%rbp),%rax
add    %rax,%rsi
xor    %edx,%edx
call   1040 <block_cipher@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<encrypt9p>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x88,%rsp
xor    %ebp,%ebp
cmp    $0x8,%edx
jl     11a5 <encrypt9p+0x85>
mov    %edx,%r15d
mov    %rsi,%rbx
mov    %rsp,%r14
mov    %r14,%rsi
call   1030 <key_setup@plt>
lea    -0x1(%r15),%ebp
imul   $0x24924925,%rbp,%rax
shr    $0x20,%rax
sub    %eax,%ebp
shr    %ebp
add    %eax,%ebp
shr    $0x2,%ebp
lea    0x0(,%rbp,8),%eax
mov    %ebp,%ecx
sub    %eax,%ecx
add    %ecx,%r15d
add    $0xffffffff,%r15d
nop
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
call   1040 <block_cipher@plt>
add    $0x7,%rbx
add    $0xffffffff,%ebp
jne    1170 <encrypt9p+0x50>
mov    $0x1,%ebp
test   %r15d,%r15d
je     11a5 <encrypt9p+0x85>
mov    %r15d,%eax
lea    (%rax,%rbx,1),%rsi
add    $0xfffffffffffffff9,%rsi
mov    %rsp,%rdi
xor    %edx,%edx
call   1040 <block_cipher@plt>
mov    %ebp,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @encrypt9p(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 %51
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
store i32 0, i32* %10
br label %26
26: ; preds = %36, %15
%27 = load i32, i32* %10
%28 = load i32, i32* %7
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %39
30: ; preds = %26
%31 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%32 = load i8*, i8** %9
%33 = call i32 @block_cipher(i8* %31, i8* %32, i32 0)
%34 = load i8*, i8** %9
%35 = getelementptr inbounds i8, i8* %34, i64 7
store i8* %35, i8** %9
br label %36
36: ; preds = %30
%37 = load i32, i32* %10
%38 = add nsw i32 %37, 1
store i32 %38, i32* %10
br label %26
39: ; preds = %26
%40 = load i32, i32* %11
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %50
42: ; preds = %39
%43 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%44 = load i8*, i8** %9
%45 = getelementptr inbounds i8, i8* %44, i64 -7
%46 = load i32, i32* %11
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %45, i64 %47
%49 = call i32 @block_cipher(i8* %43, i8* %48, i32 0)
br label %50
50: ; preds = %42, %39
store i32 1, i32* %4
br label %51
51: ; preds = %50, %14
%52 = load i32, i32* %4
ret i32 %52
}

LLVM IR (-O2):
define i32 @encrypt9p(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 %25, 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
br label %12
12: ; preds = %7, %12
%13 = phi i32 [ %17, %12 ], [ 0, %7 ]
%14 = phi i8* [ %16, %12 ], [ %1, %7 ]
%15 = call i32 @block_cipher(i8* %5, i8* %14, i32 0)
%16 = getelementptr inbounds i8, i8* %14, i64 7
%17 = add nuw nsw i32 %13, 1
%18 = icmp eq i32 %17, %11
br i1 %18, label %19, label %12
19: ; preds = %12
%20 = icmp eq i32 %10, 0
br i1 %20, label %25, label %21
21: ; preds = %19
%22 = zext i32 %10 to i64
%23 = getelementptr inbounds i8, i8* %14, i64 %22
%24 = call i32 @block_cipher(i8* %5, i8* %23, i32 0)
br label %25
25: ; preds = %19, %21, %3
%26 = phi i32 [ 0, %3 ], [ 1, %21 ], [ 1, %19 ]
ret i32 %26
}