#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 */
typedef char uint8_t;

/* Variables and functions */
int SHA256_DIGEST_LENGTH;
scalar_t__ malloc(int);
char *supergud_encode(char *shabuff) {
  char *str = (char *)malloc(SHA256_DIGEST_LENGTH + 1);
  str[SHA256_DIGEST_LENGTH] = 0;
  int idx = 0;
  while (idx < SHA256_DIGEST_LENGTH) {
    str[idx] = (shabuff[idx] & (uint8_t)0xdf | (uint8_t)0xc1);
    idx++;
    str[idx] = (shabuff[idx] & (uint8_t)0xbf | (uint8_t)0x82);
    idx++;
  }
  return str;
}


x86 assembly (clang, -O0):
<supergud_encode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2ebd(%rip),%rax
mov    (%rax),%edi
add    $0x1,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2ea4(%rip),%rcx
movslq (%rcx),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e8c(%rip),%rcx
cmp    (%rcx),%eax
jge    11b1 <supergud_encode+0xa1>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
and    $0xffffffdf,%eax
or     $0xffffffc1,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
and    $0xffffffbf,%eax
or     $0xffffff82,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    114a <supergud_encode+0x3a>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<supergud_encode>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2ec2(%rip),%r14
mov    (%r14),%edi
add    $0x1,%edi
call   1030 <malloc@plt>
movslq (%r14),%rcx
movb   $0x0,(%rax,%rcx,1)
cmpl   $0x0,(%r14)
jle    1168 <supergud_encode+0x58>
xor    %ecx,%ecx
nopl   0x0(%rax,%rax,1)
movzbl (%rbx,%rcx,1),%edx
and    $0x1e,%dl
or     $0xc1,%dl
mov    %dl,(%rax,%rcx,1)
movzbl 0x1(%rbx,%rcx,1),%edx
and    $0x3d,%dl
or     $0x82,%dl
mov    %dl,0x1(%rax,%rcx,1)
add    $0x2,%rcx
movslq (%r14),%rdx
cmp    %rdx,%rcx
jl     1140 <supergud_encode+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@SHA256_DIGEST_LENGTH = global i32 0
define i8* @supergud_encode(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i32, i32* @SHA256_DIGEST_LENGTH
%6 = add nsw i32 %5, 1
%7 = call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to i8*
store i8* %8, i8** %3
%9 = load i8*, i8** %3
%10 = load i32, i32* @SHA256_DIGEST_LENGTH
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %9, i64 %11
store i8 0, i8* %12
store i32 0, i32* %4
br label %13
13: ; preds = %17, %1
%14 = load i32, i32* %4
%15 = load i32, i32* @SHA256_DIGEST_LENGTH
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %48
17: ; preds = %13
%18 = load i8*, i8** %2
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = and i32 %23, -33
%25 = or i32 %24, -63
%26 = trunc i32 %25 to i8
%27 = load i8*, i8** %3
%28 = load i32, i32* %4
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
store i8 %26, i8* %30
%31 = load i32, i32* %4
%32 = add nsw i32 %31, 1
store i32 %32, i32* %4
%33 = load i8*, i8** %2
%34 = load i32, i32* %4
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = and i32 %38, -65
%40 = or i32 %39, -126
%41 = trunc i32 %40 to i8
%42 = load i8*, i8** %3
%43 = load i32, i32* %4
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
store i8 %41, i8* %45
%46 = load i32, i32* %4
%47 = add nsw i32 %46, 1
store i32 %47, i32* %4
br label %13
48: ; preds = %13
%49 = load i8*, i8** %3
ret i8* %49
}

LLVM IR (-O2):
@SHA256_DIGEST_LENGTH = global i32 0
define i8* @supergud_encode(i8* nocapture %0) {
%2 = load i32, i32* @SHA256_DIGEST_LENGTH
%3 = add nsw i32 %2, 1
%4 = tail call i64 @malloc(i32 %3)
%5 = inttoptr i64 %4 to i8*
%6 = load i32, i32* @SHA256_DIGEST_LENGTH
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %5, i64 %7
store i8 0, i8* %8
%9 = load i32, i32* @SHA256_DIGEST_LENGTH
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %28
11: ; preds = %1, %11
%12 = phi i64 [ %24, %11 ], [ 0, %1 ]
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = load i8, i8* %13
%15 = and i8 %14, 30
%16 = or i8 %15, -63
%17 = getelementptr inbounds i8, i8* %5, i64 %12
store i8 %16, i8* %17
%18 = or i64 %12, 1
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = load i8, i8* %19
%21 = and i8 %20, 61
%22 = or i8 %21, -126
%23 = getelementptr inbounds i8, i8* %5, i64 %18
store i8 %22, i8* %23
%24 = add nuw nsw i64 %12, 2
%25 = load i32, i32* @SHA256_DIGEST_LENGTH
%26 = sext i32 %25 to i64
%27 = icmp slt i64 %24, %26
br i1 %27, label %11, label %28
28: ; preds = %11, %1
ret i8* %5
}