#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 */
struct pc1_ctx {
  int dummy;
};

/* Variables and functions */
unsigned char pc1_encrypt(struct pc1_ctx *, unsigned char);
void pc1_encrypt_buf(struct pc1_ctx *pc1, unsigned char *buf, unsigned len) {
  unsigned i;
  for (i = 0; i < len; i++)
    buf[i] = pc1_encrypt(pc1, buf[i]);
}


x86 assembly (clang, -O0):
<pc1_encrypt_buf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    1164 <pc1_encrypt_buf+0x54>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
movzbl (%rax,%rcx,1),%esi
call   1030 <pc1_encrypt@plt>
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    112a <pc1_encrypt_buf+0x1a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pc1_encrypt_buf>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
je     114a <pc1_encrypt_buf+0x3a>
mov    %rsi,%r12
mov    %rdi,%r14
mov    %edx,%r15d
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movzbl (%r12,%rbx,1),%esi
mov    %r14,%rdi
call   1030 <pc1_encrypt@plt>
mov    %al,(%r12,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1130 <pc1_encrypt_buf+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.pc1_ctx = type { i32 }
define void @pc1_encrypt_buf(%struct.pc1_ctx* %0, i8* %1, i32 %2) {
%4 = alloca %struct.pc1_ctx*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store %struct.pc1_ctx* %0, %struct.pc1_ctx** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %7
br label %8
8: ; preds = %24, %3
%9 = load i32, i32* %7
%10 = load i32, i32* %6
%11 = icmp ult i32 %9, %10
br i1 %11, label %12, label %27
12: ; preds = %8
%13 = load %struct.pc1_ctx*, %struct.pc1_ctx** %4
%14 = load i8*, i8** %5
%15 = load i32, i32* %7
%16 = zext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8, i8* %17
%19 = call zeroext i8 @pc1_encrypt(%struct.pc1_ctx* %13, i8 zeroext %18)
%20 = load i8*, i8** %5
%21 = load i32, i32* %7
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
store i8 %19, i8* %23
br label %24
24: ; preds = %12
%25 = load i32, i32* %7
%26 = add i32 %25, 1
store i32 %26, i32* %7
br label %8
27: ; preds = %8
ret void
}

LLVM IR (-O2):
%struct.pc1_ctx = type { i32 }
define void @pc1_encrypt_buf(%struct.pc1_ctx* %0, i8* nocapture %1, i32 %2) {
%4 = icmp eq i32 %2, 0
br i1 %4, label %14, label %5
5: ; preds = %3
%6 = zext i32 %2 to i64
br label %7
7: ; preds = %5, %7
%8 = phi i64 [ 0, %5 ], [ %12, %7 ]
%9 = getelementptr inbounds i8, i8* %1, i64 %8
%10 = load i8, i8* %9
%11 = tail call zeroext i8 @pc1_encrypt(%struct.pc1_ctx* %0, i8 zeroext %10)
store i8 %11, i8* %9
%12 = add nuw nsw i64 %8, 1
%13 = icmp eq i64 %12, %6
br i1 %13, label %14, label %7
14: ; preds = %7, %3
ret void
}