#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 int uint8_t;
struct vmpc_ctx {
  int dummy;
};

/* Variables and functions */
int vmpc_yield(struct vmpc_ctx *);
int vmpc_encrypt(struct vmpc_ctx *context, uint8_t *input, uint8_t *output,
                 size_t len) {
  size_t i;
  i = 0;
  if (context == NULL)
    return (0x00000001);
  for (i = 0; i < len; ++i)
    output[i] = input[i] ^ vmpc_yield(context);
  return (0x00000000);
}


x86 assembly (clang, -O0):
<vmpc_encrypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1147 <vmpc_encrypt+0x37>
movl   $0x1,-0x4(%rbp)
jmp    119c <vmpc_encrypt+0x8c>
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    1195 <vmpc_encrypt+0x85>
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <vmpc_yield@plt>
mov    -0x34(%rbp),%edx
xor    %eax,%edx
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    114f <vmpc_encrypt+0x3f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vmpc_encrypt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     1160 <vmpc_encrypt+0x50>
mov    %rcx,%r13
test   %rcx,%rcx
je     115c <vmpc_encrypt+0x4c>
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r12,%rbp,4),%r14d
mov    %rbx,%rdi
call   1030 <vmpc_yield@plt>
xor    %r14d,%eax
mov    %eax,(%r15,%rbp,4)
add    $0x1,%rbp
cmp    %rbp,%r13
jne    1140 <vmpc_encrypt+0x30>
xor    %eax,%eax
jmp    1165 <vmpc_encrypt+0x55>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.vmpc_ctx = type { i32 }
define i32 @vmpc_encrypt(%struct.vmpc_ctx* %0, i32* %1, i32* %2, i64 %3) {
%5 = alloca i32
%6 = alloca %struct.vmpc_ctx*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i64
%10 = alloca i64
store %struct.vmpc_ctx* %0, %struct.vmpc_ctx** %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i64 %3, i64* %9
store i64 0, i64* %10
%11 = load %struct.vmpc_ctx*, %struct.vmpc_ctx** %6
%12 = icmp eq %struct.vmpc_ctx* %11, null
br i1 %12, label %13, label %14
13: ; preds = %4
store i32 1, i32* %5
br label %34
14: ; preds = %4
store i64 0, i64* %10
br label %15
15: ; preds = %30, %14
%16 = load i64, i64* %10
%17 = load i64, i64* %9
%18 = icmp ult i64 %16, %17
br i1 %18, label %19, label %33
19: ; preds = %15
%20 = load i32*, i32** %7
%21 = load i64, i64* %10
%22 = getelementptr inbounds i32, i32* %20, i64 %21
%23 = load i32, i32* %22
%24 = load %struct.vmpc_ctx*, %struct.vmpc_ctx** %6
%25 = call i32 @vmpc_yield(%struct.vmpc_ctx* %24)
%26 = xor i32 %23, %25
%27 = load i32*, i32** %8
%28 = load i64, i64* %10
%29 = getelementptr inbounds i32, i32* %27, i64 %28
store i32 %26, i32* %29
br label %30
30: ; preds = %19
%31 = load i64, i64* %10
%32 = add i64 %31, 1
store i64 %32, i64* %10
br label %15
33: ; preds = %15
store i32 0, i32* %5
br label %34
34: ; preds = %33, %13
%35 = load i32, i32* %5
ret i32 %35
}

LLVM IR (-O2):
%struct.vmpc_ctx = type { i32 }
define i32 @vmpc_encrypt(%struct.vmpc_ctx* %0, i32* nocapture %1, i32* nocapture writeonly %2, i64 %3) {
%5 = icmp eq %struct.vmpc_ctx* %0, null
br i1 %5, label %17, label %6
6: ; preds = %4
%7 = icmp eq i64 %3, 0
br i1 %7, label %17, label %8
8: ; preds = %6, %8
%9 = phi i64 [ %15, %8 ], [ 0, %6 ]
%10 = getelementptr inbounds i32, i32* %1, i64 %9
%11 = load i32, i32* %10
%12 = tail call i32 @vmpc_yield(%struct.vmpc_ctx* %0)
%13 = xor i32 %12, %11
%14 = getelementptr inbounds i32, i32* %2, i64 %9
store i32 %13, i32* %14
%15 = add nuw i64 %9, 1
%16 = icmp eq i64 %15, %3
br i1 %16, label %17, label %8
17: ; preds = %8, %6, %4
%18 = phi i32 [ 1, %4 ], [ 0, %6 ], [ 0, %8 ]
ret i32 %18
}