#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*/ printf(char *, ...);
scalar_t__ strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, scalar_t__);
int encodeblock(unsigned char *input, char *output, int oplen, int deltas,
                int debug) {
  int rc = 0;
  char encodedstr[4 + 1] = "";
  char encodingtabe[63 + 1] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                              "abcdefghijklmnopqrstuvwxyz"
                              "0123456789"
                              "-_";
  ;
  encodedstr[0] = encodingtabe[input[0] >> 2];
  encodedstr[1] =
      encodingtabe[((input[0] & 0x03) << 4) | ((input[1] & 0xf0) >> 4)];
  encodedstr[2] =
      (deltas < 2
           ? encodingtabe[((input[1] & 0x0f) << 2) | ((input[2] & 0xc0) >> 6)]
           : '=');
  encodedstr[3] = (deltas < 1 ? encodingtabe[input[2] & 0x3f] : '=');
  strncat(output, encodedstr, oplen - strlen(output));
  if (debug) {
    printf("%s", encodedstr);
    printf("\n");
  }
  return rc;
}


x86 assembly (clang, -O0):
<encodeblock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
lea    -0x25(%rbp),%rdi
xor    %esi,%esi
mov    $0x5,%edx
call   1050 <memset@plt>
lea    -0x70(%rbp),%rdi
lea    0xe71(%rip),%rsi
mov    $0x40,%edx
call   1070 <memcpy@plt>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
sar    $0x2,%eax
cltq
mov    -0x70(%rbp,%rax,1),%al
mov    %al,-0x25(%rbp)
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
and    $0x3,%eax
shl    $0x4,%eax
mov    -0x8(%rbp),%rcx
movzbl 0x1(%rcx),%ecx
and    $0xf0,%ecx
sar    $0x4,%ecx
or     %ecx,%eax
cltq
mov    -0x70(%rbp,%rax,1),%al
mov    %al,-0x24(%rbp)
cmpl   $0x2,-0x18(%rbp)
jge    120f <encodeblock+0xbf>
mov    -0x8(%rbp),%rax
movzbl 0x1(%rax),%eax
and    $0xf,%eax
shl    $0x2,%eax
mov    -0x8(%rbp),%rcx
movzbl 0x2(%rcx),%ecx
and    $0xc0,%ecx
sar    $0x6,%ecx
or     %ecx,%eax
cltq
movsbl -0x70(%rbp,%rax,1),%eax
mov    %eax,-0x74(%rbp)
jmp    121c <encodeblock+0xcc>
mov    $0x3d,%eax
mov    %eax,-0x74(%rbp)
jmp    121c <encodeblock+0xcc>
mov    -0x74(%rbp),%eax
mov    %al,-0x23(%rbp)
cmpl   $0x1,-0x18(%rbp)
jge    1246 <encodeblock+0xf6>
mov    -0x8(%rbp),%rax
movzbl 0x2(%rax),%eax
and    $0x3f,%eax
cltq
movsbl -0x70(%rbp,%rax,1),%eax
mov    %eax,-0x78(%rbp)
jmp    1253 <encodeblock+0x103>
mov    $0x3d,%eax
mov    %eax,-0x78(%rbp)
jmp    1253 <encodeblock+0x103>
mov    -0x78(%rbp),%eax
mov    %al,-0x22(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x88(%rbp)
lea    -0x25(%rbp),%rax
mov    %rax,-0x80(%rbp)
movslq -0x14(%rbp),%rax
mov    %rax,-0x90(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x90(%rbp),%rdx
mov    -0x88(%rbp),%rdi
mov    -0x80(%rbp),%rsi
sub    %rax,%rdx
call   1060 <strncat@plt>
cmpl   $0x0,-0x1c(%rbp)
je     12c4 <encodeblock+0x174>
lea    -0x25(%rbp),%rsi
lea    0xd91(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd86(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<encodeblock>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %r8d,%r14d
mov    %rsi,%r15
movb   $0x0,0x7(%rsp)
movw   $0x0,0x5(%rsp)
movzbl (%rdi),%eax
mov    %rax,%rsi
shr    $0x2,%rsi
lea    0xe96(%rip),%rbp
mov    (%rsi,%rbp,1),%bl
mov    %bl,0x3(%rsp)
shl    $0x4,%eax
and    $0x30,%eax
movzbl 0x1(%rdi),%ebx
mov    %rbx,%rsi
shr    $0x4,%rsi
or     %rax,%rsi
mov    0x0(%rbp,%rsi,1),%al
mov    %al,0x4(%rsp)
cmp    $0x2,%ecx
jge    11bb <encodeblock+0x7b>
and    $0xf,%ebx
movzbl 0x2(%rdi),%edi
mov    %rdi,%rax
shr    $0x6,%rax
lea    (%rax,%rbx,4),%rax
mov    0x0(%rbp,%rax,1),%al
mov    %al,0x5(%rsp)
mov    $0x3d,%al
cmp    $0x1,%ecx
je     11c2 <encodeblock+0x82>
and    $0x3f,%edi
mov    (%rdi,%rbp,1),%al
jmp    11c2 <encodeblock+0x82>
movb   $0x3d,0x5(%rsp)
mov    $0x3d,%al
mov    %al,0x6(%rsp)
movslq %edx,%rbp
mov    %r15,%rdi
call   1040 <strlen@plt>
sub    %rax,%rbp
lea    0x3(%rsp),%rsi
mov    %r15,%rdi
mov    %rbp,%rdx
call   1060 <strncat@plt>
test   %r14d,%r14d
je     1206 <encodeblock+0xc6>
lea    0xe50(%rip),%rdi
lea    0x3(%rsp),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.encodeblock.encodingtabe = [64 x i8] c"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
@.str = [3 x i8] c"%s\00"
@.str.1 = [2 x i8] c"\0A\00"
define i32 @encodeblock(i8* %0, i8* %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca [5 x i8]
%13 = alloca [64 x i8]
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
store i32 0, i32* %11
%14 = bitcast [5 x i8]* %12 to i8*
%15 = bitcast [64 x i8]* %13 to i8*
%16 = load i8*, i8** %6
%17 = getelementptr inbounds i8, i8* %16, i64 0
%18 = load i8, i8* %17
%19 = zext i8 %18 to i32
%20 = ashr i32 %19, 2
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [64 x i8], [64 x i8]* %13, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = getelementptr inbounds [5 x i8], [5 x i8]* %12, i64 0, i64 0
store i8 %23, i8* %24
%25 = load i8*, i8** %6
%26 = getelementptr inbounds i8, i8* %25, i64 0
%27 = load i8, i8* %26
%28 = zext i8 %27 to i32
%29 = and i32 %28, 3
%30 = shl i32 %29, 4
%31 = load i8*, i8** %6
%32 = getelementptr inbounds i8, i8* %31, i64 1
%33 = load i8, i8* %32
%34 = zext i8 %33 to i32
%35 = and i32 %34, 240
%36 = ashr i32 %35, 4
%37 = or i32 %30, %36
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [64 x i8], [64 x i8]* %13, i64 0, i64 %38
%40 = load i8, i8* %39
%41 = getelementptr inbounds [5 x i8], [5 x i8]* %12, i64 0, i64 1
store i8 %40, i8* %41
%42 = load i32, i32* %9
%43 = icmp slt i32 %42, 2
br i1 %43, label %44, label %62
44: ; preds = %5
%45 = load i8*, i8** %6
%46 = getelementptr inbounds i8, i8* %45, i64 1
%47 = load i8, i8* %46
%48 = zext i8 %47 to i32
%49 = and i32 %48, 15
%50 = shl i32 %49, 2
%51 = load i8*, i8** %6
%52 = getelementptr inbounds i8, i8* %51, i64 2
%53 = load i8, i8* %52
%54 = zext i8 %53 to i32
%55 = and i32 %54, 192
%56 = ashr i32 %55, 6
%57 = or i32 %50, %56
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [64 x i8], [64 x i8]* %13, i64 0, i64 %58
%60 = load i8, i8* %59
%61 = sext i8 %60 to i32
br label %63
62: ; preds = %5
br label %63
63: ; preds = %62, %44
%64 = phi i32 [ %61, %44 ], [ 61, %62 ]
%65 = trunc i32 %64 to i8
%66 = getelementptr inbounds [5 x i8], [5 x i8]* %12, i64 0, i64 2
store i8 %65, i8* %66
%67 = load i32, i32* %9
%68 = icmp slt i32 %67, 1
br i1 %68, label %69, label %79
69: ; preds = %63
%70 = load i8*, i8** %6
%71 = getelementptr inbounds i8, i8* %70, i64 2
%72 = load i8, i8* %71
%73 = zext i8 %72 to i32
%74 = and i32 %73, 63
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds [64 x i8], [64 x i8]* %13, i64 0, i64 %75
%77 = load i8, i8* %76
%78 = sext i8 %77 to i32
br label %80
79: ; preds = %63
br label %80
80: ; preds = %79, %69
%81 = phi i32 [ %78, %69 ], [ 61, %79 ]
%82 = trunc i32 %81 to i8
%83 = getelementptr inbounds [5 x i8], [5 x i8]* %12, i64 0, i64 3
store i8 %82, i8* %83
%84 = load i8*, i8** %7
%85 = getelementptr inbounds [5 x i8], [5 x i8]* %12, i64 0, i64 0
%86 = load i32, i32* %8
%87 = sext i32 %86 to i64
%88 = load i8*, i8** %7
%89 = call i64 @strlen(i8* %88)
%90 = sub nsw i64 %87, %89
%91 = call i32 @strncat(i8* %84, i8* %85, i64 %90)
%92 = load i32, i32* %10
%93 = icmp ne i32 %92, 0
br i1 %93, label %94, label %98
94: ; preds = %80
%95 = getelementptr inbounds [5 x i8], [5 x i8]* %12, i64 0, i64 0
%96 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %95)
%97 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %98
98: ; preds = %94, %80
%99 = load i32, i32* %11
ret i32 %99
}

LLVM IR (-O2):
@__const.encodeblock.encodingtabe = [64 x i8] c"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
@.str = [3 x i8] c"%s\00"
define i32 @encodeblock(i8* nocapture %0, i8* %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca [5 x i8]
%7 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 0
%8 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 2
%9 = load i8, i8* %0
%10 = lshr i8 %9, 2
%11 = zext i8 %10 to i64
%12 = getelementptr inbounds [64 x i8], [64 x i8]* @__const.encodeblock.encodingtabe, i64 0, i64 %11
%13 = load i8, i8* %12
store i8 %13, i8* %7
%14 = shl i8 %9, 4
%15 = and i8 %14, 48
%16 = getelementptr inbounds i8, i8* %0, i64 1
%17 = load i8, i8* %16
%18 = lshr i8 %17, 4
%19 = or i8 %18, %15
%20 = zext i8 %19 to i64
%21 = getelementptr inbounds [64 x i8], [64 x i8]* @__const.encodeblock.encodingtabe, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 1
store i8 %22, i8* %23
%24 = icmp slt i32 %3, 2
br i1 %24, label %27, label %25
25: ; preds = %5
%26 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 2
store i8 61, i8* %26
br label %44
27: ; preds = %5
%28 = shl i8 %17, 2
%29 = and i8 %28, 60
%30 = getelementptr inbounds i8, i8* %0, i64 2
%31 = load i8, i8* %30
%32 = lshr i8 %31, 6
%33 = or i8 %32, %29
%34 = zext i8 %33 to i64
%35 = getelementptr inbounds [64 x i8], [64 x i8]* @__const.encodeblock.encodingtabe, i64 0, i64 %34
%36 = load i8, i8* %35
%37 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 2
store i8 %36, i8* %37
%38 = icmp eq i32 %3, 1
br i1 %38, label %44, label %39
39: ; preds = %27
%40 = and i8 %31, 63
%41 = zext i8 %40 to i64
%42 = getelementptr inbounds [64 x i8], [64 x i8]* @__const.encodeblock.encodingtabe, i64 0, i64 %41
%43 = load i8, i8* %42
br label %44
44: ; preds = %25, %27, %39
%45 = phi i8 [ %43, %39 ], [ 61, %27 ], [ 61, %25 ]
%46 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 3
store i8 %45, i8* %46
%47 = sext i32 %2 to i64
%48 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%49 = sub nsw i64 %47, %48
%50 = call i32 @strncat(i8* %1, i8* %7, i64 %49)
%51 = icmp eq i32 %4, 0
br i1 %51, label %55, label %52
52: ; preds = %44
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %7)
%54 = call i32 @putchar(i32 10)
br label %55
55: ; preds = %52, %44
ret i32 0
}