#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 *, ...);
int decodeblock(char *input, unsigned char *output, int oplen, int debug,
                int oindex) {
  int rc = 0;
  unsigned char decodedstr[4 + 1] = "";
  decodedstr[0] = input[0] << 2 | input[1] >> 4;
  decodedstr[1] = input[1] << 4 | input[2] >> 2;
  decodedstr[2] = input[2] << 6 | input[3] >> 0;
  output[oindex - 3] = decodedstr[0];
  output[oindex - 2] = decodedstr[1];
  output[oindex - 1] = decodedstr[2];
  if (debug) {
    printf("%i ", oindex);
    printf("%02x ", decodedstr[0]);
    printf("%02x ", decodedstr[1]);
    printf("%02x ", decodedstr[2]);
    printf("\n");
  }
  return rc;
}


x86 assembly (clang, -O0):
<decodeblock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%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   1040 <memset@plt>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
shl    $0x2,%eax
mov    -0x8(%rbp),%rcx
movsbl 0x1(%rcx),%ecx
sar    $0x4,%ecx
or     %ecx,%eax
mov    %al,-0x25(%rbp)
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%eax
shl    $0x4,%eax
mov    -0x8(%rbp),%rcx
movsbl 0x2(%rcx),%ecx
sar    $0x2,%ecx
or     %ecx,%eax
mov    %al,-0x24(%rbp)
mov    -0x8(%rbp),%rax
movsbl 0x2(%rax),%eax
shl    $0x6,%eax
mov    -0x8(%rbp),%rcx
movsbl 0x3(%rcx),%ecx
sar    $0x0,%ecx
or     %ecx,%eax
mov    %al,-0x23(%rbp)
mov    -0x25(%rbp),%dl
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x3,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%dl
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x23(%rbp),%dl
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
cmpl   $0x0,-0x18(%rbp)
je     1239 <decodeblock+0x119>
mov    -0x1c(%rbp),%esi
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movzbl -0x25(%rbp),%esi
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movzbl -0x24(%rbp),%esi
lea    0xdf2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movzbl -0x23(%rbp),%esi
lea    0xde0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdd8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decodeblock>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    (%rdi),%al
mov    0x1(%rdi),%dl
shl    $0x2,%al
mov    %edx,%ebx
sar    $0x4,%bl
or     %al,%bl
shl    $0x4,%dl
mov    0x2(%rdi),%al
mov    %eax,%r15d
sar    $0x2,%r15b
or     %dl,%r15b
shl    $0x6,%al
or     0x3(%rdi),%al
movslq %r8d,%rdx
mov    %bl,-0x3(%rdx,%rsi,1)
mov    %r15b,-0x2(%rdx,%rsi,1)
mov    %al,-0x1(%rdx,%rsi,1)
test   %ecx,%ecx
je     11ae <decodeblock+0x8e>
movzbl %al,%r14d
lea    0xe95(%rip),%rdi
mov    %r8d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl %bl,%esi
lea    0xe85(%rip),%rbp
mov    %rbp,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl %r15b,%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbp,%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <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):
@.str = [4 x i8] c"%i \00"
@.str.1 = [6 x i8] c"%02x \00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @decodeblock(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]
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
%13 = bitcast [5 x i8]* %12 to i8*
%14 = load i8*, i8** %6
%15 = getelementptr inbounds i8, i8* %14, i64 0
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = shl i32 %17, 2
%19 = load i8*, i8** %6
%20 = getelementptr inbounds i8, i8* %19, i64 1
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = ashr i32 %22, 4
%24 = or i32 %18, %23
%25 = trunc i32 %24 to i8
%26 = getelementptr inbounds [5 x i8], [5 x i8]* %12, i64 0, i64 0
store i8 %25, i8* %26
%27 = load i8*, i8** %6
%28 = getelementptr inbounds i8, i8* %27, i64 1
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = shl i32 %30, 4
%32 = load i8*, i8** %6
%33 = getelementptr inbounds i8, i8* %32, i64 2
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = ashr i32 %35, 2
%37 = or i32 %31, %36
%38 = trunc i32 %37 to i8
%39 = getelementptr inbounds [5 x i8], [5 x i8]* %12, i64 0, i64 1
store i8 %38, i8* %39
%40 = load i8*, i8** %6
%41 = getelementptr inbounds i8, i8* %40, i64 2
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = shl i32 %43, 6
%45 = load i8*, i8** %6
%46 = getelementptr inbounds i8, i8* %45, i64 3
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = ashr i32 %48, 0
%50 = or i32 %44, %49
%51 = trunc i32 %50 to i8
%52 = getelementptr inbounds [5 x i8], [5 x i8]* %12, i64 0, i64 2
store i8 %51, i8* %52
%53 = getelementptr inbounds [5 x i8], [5 x i8]* %12, i64 0, i64 0
%54 = load i8, i8* %53
%55 = load i8*, i8** %7
%56 = load i32, i32* %10
%57 = sub nsw i32 %56, 3
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %55, i64 %58
store i8 %54, i8* %59
%60 = getelementptr inbounds [5 x i8], [5 x i8]* %12, i64 0, i64 1
%61 = load i8, i8* %60
%62 = load i8*, i8** %7
%63 = load i32, i32* %10
%64 = sub nsw i32 %63, 2
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8, i8* %62, i64 %65
store i8 %61, i8* %66
%67 = getelementptr inbounds [5 x i8], [5 x i8]* %12, i64 0, i64 2
%68 = load i8, i8* %67
%69 = load i8*, i8** %7
%70 = load i32, i32* %10
%71 = sub nsw i32 %70, 1
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i8, i8* %69, i64 %72
store i8 %68, i8* %73
%74 = load i32, i32* %9
%75 = icmp ne i32 %74, 0
br i1 %75, label %76, label %92
76: ; preds = %5
%77 = load i32, i32* %10
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %77)
%79 = getelementptr inbounds [5 x i8], [5 x i8]* %12, i64 0, i64 0
%80 = load i8, i8* %79
%81 = zext i8 %80 to i32
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %81)
%83 = getelementptr inbounds [5 x i8], [5 x i8]* %12, i64 0, i64 1
%84 = load i8, i8* %83
%85 = zext i8 %84 to i32
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %85)
%87 = getelementptr inbounds [5 x i8], [5 x i8]* %12, i64 0, i64 2
%88 = load i8, i8* %87
%89 = zext i8 %88 to i32
%90 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %89)
%91 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %92
92: ; preds = %76, %5
%93 = load i32, i32* %11
ret i32 %93
}

LLVM IR (-O2):
@.str = [4 x i8] c"%i \00"
@.str.1 = [6 x i8] c"%02x \00"
define i32 @decodeblock(i8* nocapture %0, i8* nocapture writeonly %1, i32 %2, i32 %3, i32 %4) {
%6 = load i8, i8* %0
%7 = shl i8 %6, 2
%8 = getelementptr inbounds i8, i8* %0, i64 1
%9 = load i8, i8* %8
%10 = ashr i8 %9, 4
%11 = or i8 %10, %7
%12 = shl i8 %9, 4
%13 = getelementptr inbounds i8, i8* %0, i64 2
%14 = load i8, i8* %13
%15 = ashr i8 %14, 2
%16 = or i8 %15, %12
%17 = shl i8 %14, 6
%18 = getelementptr inbounds i8, i8* %0, i64 3
%19 = load i8, i8* %18
%20 = or i8 %17, %19
%21 = add nsw i32 %4, -3
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %1, i64 %22
store i8 %11, i8* %23
%24 = add nsw i32 %4, -2
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %1, i64 %25
store i8 %16, i8* %26
%27 = add nsw i32 %4, -1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %1, i64 %28
store i8 %20, i8* %29
%30 = icmp eq i32 %3, 0
br i1 %30, label %40, label %31
31: ; preds = %5
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %4)
%33 = zext i8 %11 to i32
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %33)
%35 = zext i8 %16 to i32
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %35)
%37 = zext i8 %20 to i32
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %37)
%39 = tail call i32 @putchar(i32 10)
br label %40
40: ; preds = %31, %5
ret i32 0
}