#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 */
unsigned char *malloc(size_t);
size_t otrl_base64_decode(unsigned char *, char *, size_t);
char *strchr(char *, char);
char *strstr(char const *, char *);
int otrl_base64_otr_decode(const char *msg, unsigned char **bufp,
                           size_t *lenp) {
  char *otrtag, *endtag;
  size_t msglen, rawlen;
  unsigned char *rawmsg;
  otrtag = strstr(msg, "?OTR:");
  if (!otrtag) {
    return -2;
  }
  endtag = strchr(otrtag, '.');
  if (endtag) {
    msglen = endtag - otrtag;
  } else {
    return -2;
  }
  otrtag += 5;
  msglen -= 5;
  rawlen = (((msglen + 4 - 1) / 4) * 3);
  rawmsg = malloc(rawlen);
  if (!rawmsg && rawlen > 0) {
    return -1;
  }
  rawlen = otrl_base64_decode(rawmsg, otrtag, msglen);
  *bufp = rawmsg;
  *lenp = rawlen;
  return 0;
}


x86 assembly (clang, -O0):
<otrl_base64_otr_decode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea1(%rip),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    117f <otrl_base64_otr_decode+0x3f>
movl   $0xfffffffe,-0x4(%rbp)
jmp    124d <otrl_base64_otr_decode+0x10d>
mov    -0x28(%rbp),%rdi
mov    $0x2e,%esi
call   1030 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11b0 <otrl_base64_otr_decode+0x70>
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x38(%rbp)
jmp    11bc <otrl_base64_otr_decode+0x7c>
movl   $0xfffffffe,-0x4(%rbp)
jmp    124d <otrl_base64_otr_decode+0x10d>
mov    -0x28(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x28(%rbp)
mov    -0x38(%rbp),%rax
sub    $0x5,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
add    $0x4,%rax
sub    $0x1,%rax
shr    $0x2,%rax
imul   $0x3,%rax,%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    121b <otrl_base64_otr_decode+0xdb>
cmpq   $0x0,-0x40(%rbp)
jbe    121b <otrl_base64_otr_decode+0xdb>
movl   $0xffffffff,-0x4(%rbp)
jmp    124d <otrl_base64_otr_decode+0x10d>
mov    -0x48(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1040 <otrl_base64_decode@plt>
mov    %rax,-0x40(%rbp)
mov    -0x48(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x40(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<otrl_base64_otr_decode>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
lea    0xea8(%rip),%rsi
call   1060 <strstr@plt>
mov    $0xfffffffe,%ebp
test   %rax,%rax
je     11d0 <otrl_base64_otr_decode+0x90>
mov    %rax,%rbx
mov    %r14,(%rsp)
mov    %rax,%rdi
mov    $0x2e,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     11d0 <otrl_base64_otr_decode+0x90>
mov    %rax,%r12
sub    %rbx,%r12
lea    -0x2(%r12),%r14
mov    %r14,%rax
shr    $0x2,%rax
lea    (%rax,%rax,2),%rdi
call   1050 <malloc@plt>
mov    %rax,%r13
test   %rax,%rax
jne    11ae <otrl_base64_otr_decode+0x6e>
mov    $0xffffffff,%ebp
cmp    $0x3,%r14
ja     11d0 <otrl_base64_otr_decode+0x90>
add    $0xfffffffffffffffb,%r12
add    $0x5,%rbx
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1040 <otrl_base64_decode@plt>
mov    %r13,(%r15)
mov    (%rsp),%rcx
mov    %rax,(%rcx)
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"?OTR:\00"
define i32 @otrl_base64_otr_decode(i8* %0, i8** %1, i64* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i64*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i64
%12 = alloca i8*
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i64* %2, i64** %7
%13 = load i8*, i8** %5
%14 = call i8* @strstr(i8* %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i8* %14, i8** %8
%15 = load i8*, i8** %8
%16 = icmp ne i8* %15, null
br i1 %16, label %18, label %17
17: ; preds = %3
store i32 -2, i32* %4
br label %57
18: ; preds = %3
%19 = load i8*, i8** %8
%20 = call i8* @strchr(i8* %19, i8 signext 46)
store i8* %20, i8** %9
%21 = load i8*, i8** %9
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %29
23: ; preds = %18
%24 = load i8*, i8** %9
%25 = load i8*, i8** %8
%26 = ptrtoint i8* %24 to i64
%27 = ptrtoint i8* %25 to i64
%28 = sub i64 %26, %27
store i64 %28, i64* %10
br label %30
29: ; preds = %18
store i32 -2, i32* %4
br label %57
30: ; preds = %23
%31 = load i8*, i8** %8
%32 = getelementptr inbounds i8, i8* %31, i64 5
store i8* %32, i8** %8
%33 = load i64, i64* %10
%34 = sub i64 %33, 5
store i64 %34, i64* %10
%35 = load i64, i64* %10
%36 = add i64 %35, 4
%37 = sub i64 %36, 1
%38 = udiv i64 %37, 4
%39 = mul i64 %38, 3
store i64 %39, i64* %11
%40 = load i64, i64* %11
%41 = call i8* @malloc(i64 %40)
store i8* %41, i8** %12
%42 = load i8*, i8** %12
%43 = icmp ne i8* %42, null
br i1 %43, label %48, label %44
44: ; preds = %30
%45 = load i64, i64* %11
%46 = icmp ugt i64 %45, 0
br i1 %46, label %47, label %48
47: ; preds = %44
store i32 -1, i32* %4
br label %57
48: ; preds = %44, %30
%49 = load i8*, i8** %12
%50 = load i8*, i8** %8
%51 = load i64, i64* %10
%52 = call i64 @otrl_base64_decode(i8* %49, i8* %50, i64 %51)
store i64 %52, i64* %11
%53 = load i8*, i8** %12
%54 = load i8**, i8*** %6
store i8* %53, i8** %54
%55 = load i64, i64* %11
%56 = load i64*, i64** %7
store i64 %55, i64* %56
store i32 0, i32* %4
br label %57
57: ; preds = %48, %47, %29, %17
%58 = load i32, i32* %4
ret i32 %58
}

LLVM IR (-O2):
@.str = [6 x i8] c"?OTR:\00"
define i32 @otrl_base64_otr_decode(i8* %0, i8** nocapture writeonly %1, i64* nocapture writeonly %2) {
%4 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %24, label %6
6: ; preds = %3
%7 = tail call i8* @strchr(i8* %4, i8 signext 46)
%8 = icmp eq i8* %7, null
br i1 %8, label %24, label %9
9: ; preds = %6
%10 = ptrtoint i8* %7 to i64
%11 = ptrtoint i8* %4 to i64
%12 = sub i64 %10, %11
%13 = add i64 %12, -2
%14 = lshr i64 %13, 2
%15 = mul nuw i64 %14, 3
%16 = tail call i8* @malloc(i64 %15)
%17 = icmp eq i8* %16, null
%18 = icmp ugt i64 %13, 3
%19 = select i1 %17, i1 %18, i1 false
br i1 %19, label %24, label %20
20: ; preds = %9
%21 = add i64 %12, -5
%22 = getelementptr inbounds i8, i8* %4, i64 5
%23 = tail call i64 @otrl_base64_decode(i8* %16, i8* %22, i64 %21)
store i8* %16, i8** %1
store i64 %23, i64* %2
br label %24
24: ; preds = %9, %6, %3, %20
%25 = phi i32 [ 0, %20 ], [ -2, %3 ], [ -2, %6 ], [ -1, %9 ]
ret i32 %25
}