#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*/ assert(int);
int /*<<< orphan*/ base64_encode(char *, char *, int);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
void pg_generate(const char *in, char *out, short required_length) {
  int required_bytes = (required_length >> 2) * 3;
  assert(required_bytes <= (((64))));
  char *blk = (char *)malloc(required_bytes);
  memset(blk, 0, required_bytes);
  for (int i = 0; i < (((64))); i++) {
    blk[i % required_bytes] ^= in[i];
  }
  base64_encode(out, blk, required_bytes);
  out[required_length] = '\0';
  free(blk);
}


x86 assembly (clang, -O0):
<pg_generate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dx,%ax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %ax,-0x12(%rbp)
movswl -0x12(%rbp),%eax
sar    $0x2,%eax
imul   $0x3,%eax,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x40,-0x18(%rbp)
setle  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x18(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%edx
xor    %esi,%esi
call   1040 <memset@plt>
movl   $0x0,-0x24(%rbp)
cmpl   $0x40,-0x24(%rbp)
jge    11e9 <pg_generate+0x99>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x24(%rbp),%eax
cltd
idivl  -0x18(%rbp)
mov    -0x30(%rbp),%rax
movslq %edx,%rcx
movsbl (%rax,%rcx,1),%edx
xor    %esi,%edx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11a6 <pg_generate+0x56>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1070 <base64_encode@plt>
mov    -0x10(%rbp),%rax
movswq -0x12(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pg_generate>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%r12
mov    %edx,%eax
sar    $0x2,%eax
lea    (%rax,%rax,2),%eax
movswl %ax,%r13d
xor    %edi,%edi
cmp    $0x41,%r13w
setl   %dil
call   1050 <assert@plt>
mov    %r13d,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
xor    %ebp,%ebp
mov    %rax,%rdi
xor    %esi,%esi
mov    %r13d,%edx
call   1040 <memset@plt>
nopw   0x0(%rax,%rax,1)
movzbl (%r12,%rbp,1),%ecx
mov    %ebp,%eax
cltd
idiv   %r13d
xor    %cl,(%rbx,%rdx,1)
movzbl 0x1(%r12,%rbp,1),%ecx
lea    0x1(%rbp),%eax
cltd
idiv   %r13d
xor    %cl,(%rbx,%rdx,1)
add    $0x2,%rbp
cmp    $0x40,%rbp
jne    11a0 <pg_generate+0x50>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r13d,%edx
call   1070 <base64_encode@plt>
movswq %r15w,%rax
movb   $0x0,(%r14,%rax,1)
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
define void @pg_generate(i8* %0, i8* %1, i16 signext %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i16
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i16 %2, i16* %6
%10 = load i16, i16* %6
%11 = sext i16 %10 to i32
%12 = ashr i32 %11, 2
%13 = mul nsw i32 %12, 3
store i32 %13, i32* %7
%14 = load i32, i32* %7
%15 = icmp sle i32 %14, 64
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = load i32, i32* %7
%19 = call i64 @malloc(i32 %18)
%20 = inttoptr i64 %19 to i8*
store i8* %20, i8** %8
%21 = load i8*, i8** %8
%22 = load i32, i32* %7
%23 = call i32 @memset(i8* %21, i32 0, i32 %22)
store i32 0, i32* %9
br label %24
24: ; preds = %44, %3
%25 = load i32, i32* %9
%26 = icmp slt i32 %25, 64
br i1 %26, label %27, label %47
27: ; preds = %24
%28 = load i8*, i8** %4
%29 = load i32, i32* %9
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = load i8*, i8** %8
%35 = load i32, i32* %9
%36 = load i32, i32* %7
%37 = srem i32 %35, %36
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %34, i64 %38
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = xor i32 %41, %33
%43 = trunc i32 %42 to i8
store i8 %43, i8* %39
br label %44
44: ; preds = %27
%45 = load i32, i32* %9
%46 = add nsw i32 %45, 1
store i32 %46, i32* %9
br label %24
47: ; preds = %24
%48 = load i8*, i8** %5
%49 = load i8*, i8** %8
%50 = load i32, i32* %7
%51 = call i32 @base64_encode(i8* %48, i8* %49, i32 %50)
%52 = load i8*, i8** %5
%53 = load i16, i16* %6
%54 = sext i16 %53 to i64
%55 = getelementptr inbounds i8, i8* %52, i64 %54
store i8 0, i8* %55
%56 = load i8*, i8** %8
%57 = call i32 @free(i8* %56)
ret void
}

LLVM IR (-O2):
define void @pg_generate(i8* nocapture %0, i8* %1, i16 signext %2) {
%4 = ashr i16 %2, 2
%5 = mul nsw i16 %4, 3
%6 = sext i16 %5 to i32
%7 = icmp slt i16 %5, 65
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = tail call i64 @malloc(i32 %6)
%11 = inttoptr i64 %10 to i8*
%12 = tail call i32 @memset(i8* %11, i32 0, i32 %6)
br label %18
13: ; preds = %18
%14 = tail call i32 @base64_encode(i8* %1, i8* %11, i32 %6)
%15 = sext i16 %2 to i64
%16 = getelementptr inbounds i8, i8* %1, i64 %15
store i8 0, i8* %16
%17 = tail call i32 @free(i8* %11)
ret void
18: ; preds = %18, %3
%19 = phi i64 [ 0, %3 ], [ %37, %18 ]
%20 = getelementptr inbounds i8, i8* %0, i64 %19
%21 = load i8, i8* %20
%22 = trunc i64 %19 to i32
%23 = srem i32 %22, %6
%24 = zext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %11, i64 %24
%26 = load i8, i8* %25
%27 = xor i8 %26, %21
store i8 %27, i8* %25
%28 = or i64 %19, 1
%29 = getelementptr inbounds i8, i8* %0, i64 %28
%30 = load i8, i8* %29
%31 = trunc i64 %28 to i32
%32 = srem i32 %31, %6
%33 = zext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %11, i64 %33
%35 = load i8, i8* %34
%36 = xor i8 %35, %30
store i8 %36, i8* %34
%37 = add nuw nsw i64 %19, 2
%38 = icmp eq i64 %37, 64
br i1 %38, label %13, label %18
}