#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 decrypt_byte(unsigned long *);
int /*<<< orphan*/ update_keys(unsigned long *, char);
void encrypt_buf(char *buf, unsigned int bufsize, unsigned long keys[3]) {
  int t;
  while (bufsize--) {
    t = decrypt_byte(keys);
    update_keys(keys, *buf);
    *buf++ ^= t;
  }
}


x86 assembly (clang, -O0):
<encrypt_buf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x0,%eax
je     1181 <encrypt_buf+0x61>
mov    -0x18(%rbp),%rdi
call   1040 <decrypt_byte@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rax
movsbl (%rax),%esi
call   1030 <update_keys@plt>
mov    -0x1c(%rbp),%edx
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%ecx
xor    %edx,%ecx
mov    %cl,(%rax)
jmp    1133 <encrypt_buf+0x13>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<encrypt_buf>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %esi,%esi
je     1164 <encrypt_buf+0x44>
mov    %rdx,%r14
mov    %rdi,%r12
mov    %esi,%r15d
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1040 <decrypt_byte@plt>
mov    %eax,%ebp
movsbl (%r12,%rbx,1),%esi
mov    %r14,%rdi
call   1030 <update_keys@plt>
xor    %bpl,(%r12,%rbx,1)
add    $0x1,%rbx
cmp    %ebx,%r15d
jne    1140 <encrypt_buf+0x20>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @encrypt_buf(i8* %0, i32 %1, i64* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i64*
%7 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i64* %2, i64** %6
br label %8
8: ; preds = %12, %3
%9 = load i32, i32* %5
%10 = add i32 %9, -1
store i32 %10, i32* %5
%11 = icmp ne i32 %9, 0
br i1 %11, label %12, label %26
12: ; preds = %8
%13 = load i64*, i64** %6
%14 = call i32 @decrypt_byte(i64* %13)
store i32 %14, i32* %7
%15 = load i64*, i64** %6
%16 = load i8*, i8** %4
%17 = load i8, i8* %16
%18 = call i32 @update_keys(i64* %15, i8 signext %17)
%19 = load i32, i32* %7
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %4
%22 = load i8, i8* %20
%23 = sext i8 %22 to i32
%24 = xor i32 %23, %19
%25 = trunc i32 %24 to i8
store i8 %25, i8* %20
br label %8
26: ; preds = %8
ret void
}

LLVM IR (-O2):
define void @encrypt_buf(i8* nocapture %0, i32 %1, i64* %2) {
%4 = icmp eq i32 %1, 0
br i1 %4, label %17, label %5
5: ; preds = %3, %5
%6 = phi i8* [ %12, %5 ], [ %0, %3 ]
%7 = phi i32 [ %8, %5 ], [ %1, %3 ]
%8 = add i32 %7, -1
%9 = tail call i32 @decrypt_byte(i64* %2)
%10 = load i8, i8* %6
%11 = tail call i32 @update_keys(i64* %2, i8 signext %10)
%12 = getelementptr inbounds i8, i8* %6, i64 1
%13 = load i8, i8* %6
%14 = trunc i32 %9 to i8
%15 = xor i8 %13, %14
store i8 %15, i8* %6
%16 = icmp eq i32 %8, 0
br i1 %16, label %17, label %5
17: ; preds = %5, %3
ret void
}