#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 int /*<<< orphan*/ u_char;

/* Variables and functions */
int b64_ntop(int /*<<< orphan*/ const *, size_t, char *, size_t);
int encode_hixie(u_char const *src, size_t srclength, char *target,
                 size_t targsize) {
  int sz = 0, len = 0;
  target[sz++] = '\x00';
  len = b64_ntop(src, srclength, target + sz, targsize - sz);
  if (len < 0) {
    return len;
  }
  sz += len;
  target[sz++] = '\xff';
  return sz;
}


x86 assembly (clang, -O0):
<encode_hixie>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x2c(%rbp)
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
movslq -0x2c(%rbp),%rax
add    %rax,%rdx
mov    -0x28(%rbp),%rcx
movslq -0x2c(%rbp),%rax
sub    %rax,%rcx
call   1030 <b64_ntop@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jge    1187 <encode_hixie+0x77>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ac <encode_hixie+0x9c>
mov    -0x30(%rbp),%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x2c(%rbp)
movslq %ecx,%rcx
movb   $0xff,(%rax,%rcx,1)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<encode_hixie>:
push   %rbx
mov    %rdx,%rbx
movb   $0x0,(%rdx)
add    $0x1,%rdx
add    $0xffffffffffffffff,%rcx
call   1030 <b64_ntop@plt>
test   %eax,%eax
js     1132 <encode_hixie+0x22>
mov    %eax,%ecx
add    $0x2,%eax
movb   $0xff,0x1(%rcx,%rbx,1)
pop    %rbx
ret

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

LLVM IR (-O2):
define i32 @encode_hixie(i32* %0, i64 %1, i8* %2, i64 %3) {
store i8 0, i8* %2
%5 = getelementptr inbounds i8, i8* %2, i64 1
%6 = add i64 %3, -1
%7 = tail call i32 @b64_ntop(i32* %0, i64 %1, i8* %5, i64 %6)
%8 = icmp slt i32 %7, 0
br i1 %8, label %14, label %9
9: ; preds = %4
%10 = add nuw nsw i32 %7, 1
%11 = add nuw nsw i32 %7, 2
%12 = zext i32 %10 to i64
%13 = getelementptr inbounds i8, i8* %2, i64 %12
store i8 -1, i8* %13
br label %14
14: ; preds = %4, %9
%15 = phi i32 [ %11, %9 ], [ %7, %4 ]
ret i32 %15
}