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


x86 assembly (clang, -O0):
<decrypt_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 <decrypt_buf+0x61>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <decrypt_byte@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%edx
mov    -0x8(%rbp),%rcx
mov    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
movsbl (%rcx),%eax
xor    %edx,%eax
mov    %al,(%rcx)
movsbl %al,%esi
call   1030 <update_keys@plt>
jmp    1133 <decrypt_buf+0x13>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decrypt_buf>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
je     1164 <decrypt_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>
xor    (%r12,%rbx,1),%al
mov    %al,(%r12,%rbx,1)
movsbl %al,%esi
mov    %r14,%rdi
call   1030 <update_keys@plt>
add    $0x1,%rbx
cmp    %ebx,%r15d
jne    1140 <decrypt_buf+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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