#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 strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, int);
int encodeblock(char *input, char *output, int oplen) {
  int rc = 0, iplen = 0;
  char encodedstr[4 + 1] = "";
  char encodingtabe[63 + 1] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                              "abcdefghijklmnopqrstuvwxyz"
                              "0123456789"
                              "+/";
  ;
  iplen = strlen(input);
  encodedstr[0] = encodingtabe[input[0] >> 2];
  encodedstr[1] =
      encodingtabe[((input[0] & 0x03) << 4) | ((input[1] & 0xf0) >> 4)];
  encodedstr[2] =
      (iplen > 1
           ? encodingtabe[((input[1] & 0x0f) << 2) | ((input[2] & 0xc0) >> 6)]
           : '=');
  encodedstr[3] = (iplen > 2 ? encodingtabe[input[2] & 0x3f] : '=');
  strncat(output, encodedstr, oplen - strlen(output));
  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)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    -0x21(%rbp),%rdi
xor    %esi,%esi
mov    $0x5,%edx
call   1040 <memset@plt>
lea    -0x70(%rbp),%rdi
lea    0xe81(%rip),%rsi
mov    $0x40,%edx
call   1060 <memcpy@plt>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
sar    $0x2,%eax
cltq
mov    -0x70(%rbp,%rax,1),%al
mov    %al,-0x21(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
and    $0x3,%eax
shl    $0x4,%eax
mov    -0x8(%rbp),%rcx
movsbl 0x1(%rcx),%ecx
and    $0xf0,%ecx
sar    $0x4,%ecx
or     %ecx,%eax
cltq
mov    -0x70(%rbp,%rax,1),%al
mov    %al,-0x20(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jle    120b <encodeblock+0xcb>
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%eax
and    $0xf,%eax
shl    $0x2,%eax
mov    -0x8(%rbp),%rcx
movsbl 0x2(%rcx),%ecx
and    $0xc0,%ecx
sar    $0x6,%ecx
or     %ecx,%eax
cltq
movsbl -0x70(%rbp,%rax,1),%eax
mov    %eax,-0x74(%rbp)
jmp    1218 <encodeblock+0xd8>
mov    $0x3d,%eax
mov    %eax,-0x74(%rbp)
jmp    1218 <encodeblock+0xd8>
mov    -0x74(%rbp),%eax
mov    %al,-0x1f(%rbp)
cmpl   $0x2,-0x1c(%rbp)
jle    1242 <encodeblock+0x102>
mov    -0x8(%rbp),%rax
movsbl 0x2(%rax),%eax
and    $0x3f,%eax
cltq
movsbl -0x70(%rbp,%rax,1),%eax
mov    %eax,-0x78(%rbp)
jmp    124f <encodeblock+0x10f>
mov    $0x3d,%eax
mov    %eax,-0x78(%rbp)
jmp    124f <encodeblock+0x10f>
mov    -0x78(%rbp),%eax
mov    %al,-0x1e(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x88(%rbp)
lea    -0x21(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x8c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x8c(%rbp),%edx
mov    -0x88(%rbp),%rdi
mov    -0x80(%rbp),%rsi
sub    %eax,%edx
call   1050 <strncat@plt>
mov    -0x18(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<encodeblock>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
movb   $0x0,0xf(%rsp)
movw   $0x0,0xd(%rsp)
call   1030 <strlen@plt>
movzbl (%rbx),%esi
mov    %esi,%ecx
sar    $0x2,%cl
movsbq %cl,%rdx
lea    0xeac(%rip),%r8
mov    (%rdx,%r8,1),%dl
mov    %dl,0xb(%rsp)
shl    $0x4,%esi
and    $0x30,%esi
movzbl 0x1(%rbx),%edx
mov    %rdx,%rdi
shr    $0x4,%rdi
or     %rsi,%rdi
mov    (%r8,%rdi,1),%cl
mov    %cl,0xc(%rsp)
cmp    $0x1,%eax
jle    11a7 <encodeblock+0x87>
and    $0xf,%edx
movzbl 0x2(%rbx),%esi
mov    %rsi,%rcx
shr    $0x6,%rcx
lea    (%rcx,%rdx,4),%rcx
mov    (%r8,%rcx,1),%cl
mov    %cl,0xd(%rsp)
mov    $0x3d,%dl
cmp    $0x2,%eax
je     11ae <encodeblock+0x8e>
and    $0x3f,%esi
mov    (%rsi,%r8,1),%dl
jmp    11ae <encodeblock+0x8e>
movb   $0x3d,0xd(%rsp)
mov    $0x3d,%dl
mov    %dl,0xe(%rsp)
mov    %r14,%rdi
call   1030 <strlen@plt>
sub    %eax,%ebp
lea    0xb(%rsp),%rsi
mov    %r14,%rdi
mov    %ebp,%edx
call   1040 <strncat@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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