#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 unsigned int uint32_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EOF;
int /*<<< orphan*/ encode_tuple(unsigned int, int, int, int *, int);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ putc_wrap(char, int, int *);
void ascii85_encode(FILE *fp, int delims, int wrap, int y_abbr) {
  int c, count = 0, len = 0;
  uint32_t tuple = 0;
  if (delims) {
    putc_wrap('<', wrap, &len);
    putc_wrap('~', wrap, &len);
  }
  for (;;) {
    c = getc(fp);
    if (c != EOF) {
      tuple |= ((unsigned int)c) << ((3 - count++) * 8);
      if (count < 4)
        continue;
    } else if (count == 0)
      break;
    encode_tuple(tuple, count, wrap, &len, y_abbr);
    if (c == EOF)
      break;
    tuple = 0;
    count = 0;
  }
  if (delims) {
    putc_wrap('~', wrap, &len);
    putc_wrap('>', wrap, &len);
  }
}


x86 assembly (clang, -O0):
<ascii85_encode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1186 <ascii85_encode+0x56>
mov    -0x10(%rbp),%esi
mov    $0x3c,%edi
lea    -0x20(%rbp),%rdx
call   1030 <putc_wrap@plt>
mov    -0x10(%rbp),%esi
mov    $0x7e,%edi
lea    -0x20(%rbp),%rdx
call   1030 <putc_wrap@plt>
jmp    118b <ascii85_encode+0x5b>
mov    -0x8(%rbp),%rdi
call   1050 <getc@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    0x2e47(%rip),%rcx
cmp    (%rcx),%eax
je     11dd <ascii85_encode+0xad>
mov    -0x18(%rbp),%eax
mov    -0x1c(%rbp),%edx
mov    %edx,%ecx
add    $0x1,%ecx
mov    %ecx,-0x1c(%rbp)
mov    $0x3,%ecx
sub    %edx,%ecx
shl    $0x3,%ecx
shl    %cl,%eax
or     -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x4,-0x1c(%rbp)
jge    11d8 <ascii85_encode+0xa8>
jmp    118b <ascii85_encode+0x5b>
jmp    11f1 <ascii85_encode+0xc1>
cmpl   $0x0,-0x1c(%rbp)
jne    11ec <ascii85_encode+0xbc>
jmp    1231 <ascii85_encode+0x101>
jmp    11f1 <ascii85_encode+0xc1>
mov    -0x24(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%r8d
lea    -0x20(%rbp),%rcx
call   1040 <encode_tuple@plt>
mov    -0x18(%rbp),%eax
mov    0x2dd7(%rip),%rcx
cmp    (%rcx),%eax
jne    121e <ascii85_encode+0xee>
jmp    1231 <ascii85_encode+0x101>
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x1c(%rbp)
jmp    118b <ascii85_encode+0x5b>
cmpl   $0x0,-0xc(%rbp)
je     125d <ascii85_encode+0x12d>
mov    -0x10(%rbp),%esi
mov    $0x7e,%edi
lea    -0x20(%rbp),%rdx
call   1030 <putc_wrap@plt>
mov    -0x10(%rbp),%esi
mov    $0x3e,%edi
lea    -0x20(%rbp),%rdx
call   1030 <putc_wrap@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ascii85_encode>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,0x14(%rsp)
mov    %edx,%r13d
mov    %rdi,%rbp
movl   $0x0,0xc(%rsp)
mov    %esi,0x10(%rsp)
test   %esi,%esi
je     117d <ascii85_encode+0x4d>
lea    0xc(%rsp),%rbx
mov    $0x3c,%edi
mov    %r13d,%esi
mov    %rbx,%rdx
call   1030 <putc_wrap@plt>
mov    $0x7e,%edi
mov    %r13d,%esi
mov    %rbx,%rdx
call   1030 <putc_wrap@plt>
xor    %ebx,%ebx
mov    0x2e62(%rip),%r15
xor    %r14d,%r14d
jmp    11ad <ascii85_encode+0x7d>
nopl   0x0(%rax,%rax,1)
lea    0x0(,%rbx,8),%eax
mov    $0x18,%cl
sub    %al,%cl
mov    %r12d,%eax
shl    %cl,%eax
lea    0x1(%rbx),%ecx
or     %eax,%r14d
cmp    $0x3,%ebx
mov    %ecx,%ebx
jge    11c1 <ascii85_encode+0x91>
mov    %rbp,%rdi
call   1050 <getc@plt>
mov    %eax,%r12d
cmp    (%r15),%eax
jne    1190 <ascii85_encode+0x60>
test   %ebx,%ebx
je     11e8 <ascii85_encode+0xb8>
mov    %r14d,%edi
mov    %ebx,%esi
mov    %r13d,%edx
lea    0xc(%rsp),%rcx
mov    0x14(%rsp),%r8d
call   1040 <encode_tuple@plt>
mov    $0x0,%ebx
mov    $0x0,%r14d
cmp    (%r15),%r12d
jne    11ad <ascii85_encode+0x7d>
cmpl   $0x0,0x10(%rsp)
je     1214 <ascii85_encode+0xe4>
lea    0xc(%rsp),%rbx
mov    $0x7e,%edi
mov    %r13d,%esi
mov    %rbx,%rdx
call   1030 <putc_wrap@plt>
mov    $0x3e,%edi
mov    %r13d,%esi
mov    %rbx,%rdx
call   1030 <putc_wrap@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
define void @ascii85_encode(i32* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store i32 0, i32* %10
store i32 0, i32* %11
store i32 0, i32* %12
%13 = load i32, i32* %6
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %4
%16 = load i32, i32* %7
%17 = call i32 @putc_wrap(i8 signext 60, i32 %16, i32* %11)
%18 = load i32, i32* %7
%19 = call i32 @putc_wrap(i8 signext 126, i32 %18, i32* %11)
br label %20
20: ; preds = %15, %4
br label %21
21: ; preds = %55, %38, %20
%22 = load i32*, i32** %5
%23 = call i32 @getc(i32* %22)
store i32 %23, i32* %9
%24 = load i32, i32* %9
%25 = load i32, i32* @EOF
%26 = icmp ne i32 %24, %25
br i1 %26, label %27, label %40
27: ; preds = %21
%28 = load i32, i32* %9
%29 = load i32, i32* %10
%30 = add nsw i32 %29, 1
store i32 %30, i32* %10
%31 = sub nsw i32 3, %29
%32 = mul nsw i32 %31, 8
%33 = shl i32 %28, %32
%34 = load i32, i32* %12
%35 = or i32 %34, %33
store i32 %35, i32* %12
%36 = load i32, i32* %10
%37 = icmp slt i32 %36, 4
br i1 %37, label %38, label %39
38: ; preds = %27
br label %21
39: ; preds = %27
br label %45
40: ; preds = %21
%41 = load i32, i32* %10
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %40
br label %56
44: ; preds = %40
br label %45
45: ; preds = %44, %39
%46 = load i32, i32* %12
%47 = load i32, i32* %10
%48 = load i32, i32* %7
%49 = load i32, i32* %8
%50 = call i32 @encode_tuple(i32 %46, i32 %47, i32 %48, i32* %11, i32 %49)
%51 = load i32, i32* %9
%52 = load i32, i32* @EOF
%53 = icmp eq i32 %51, %52
br i1 %53, label %54, label %55
54: ; preds = %45
br label %56
55: ; preds = %45
store i32 0, i32* %12
store i32 0, i32* %10
br label %21
56: ; preds = %54, %43
%57 = load i32, i32* %6
%58 = icmp ne i32 %57, 0
br i1 %58, label %59, label %64
59: ; preds = %56
%60 = load i32, i32* %7
%61 = call i32 @putc_wrap(i8 signext 126, i32 %60, i32* %11)
%62 = load i32, i32* %7
%63 = call i32 @putc_wrap(i8 signext 62, i32 %62, i32* %11)
br label %64
64: ; preds = %59, %56
ret void
}

LLVM IR (-O2):
@EOF = global i32 0
define void @ascii85_encode(i32* nocapture %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%7 = icmp eq i32 %1, 0
br i1 %7, label %11, label %8
8: ; preds = %4
%9 = call i32 @putc_wrap(i8 signext 60, i32 %2, i32* %5)
%10 = call i32 @putc_wrap(i8 signext 126, i32 %2, i32* %5)
br label %11
11: ; preds = %8, %4
br label %12
12: ; preds = %25, %11
%13 = phi i32 [ 0, %11 ], [ %26, %25 ]
%14 = phi i32 [ 0, %11 ], [ %27, %25 ]
%15 = call i32 @getc(i32* %0)
%16 = load i32, i32* @EOF
%17 = icmp eq i32 %15, %16
br i1 %17, label %28, label %18
18: ; preds = %12
%19 = add nsw i32 %13, 1
%20 = mul i32 %13, -8
%21 = add i32 %20, 24
%22 = shl i32 %15, %21
%23 = or i32 %22, %14
%24 = icmp slt i32 %13, 3
br i1 %24, label %25, label %30
25: ; preds = %18, %30
%26 = phi i32 [ %19, %18 ], [ 0, %30 ]
%27 = phi i32 [ %23, %18 ], [ 0, %30 ]
br label %12
28: ; preds = %12
%29 = icmp eq i32 %13, 0
br i1 %29, label %36, label %30
30: ; preds = %28, %18
%31 = phi i32 [ %19, %18 ], [ %13, %28 ]
%32 = phi i32 [ %23, %18 ], [ %14, %28 ]
%33 = call i32 @encode_tuple(i32 %32, i32 %31, i32 %2, i32* %5, i32 %3)
%34 = load i32, i32* @EOF
%35 = icmp eq i32 %15, %34
br i1 %35, label %36, label %25
36: ; preds = %30, %28
br i1 %7, label %40, label %37
37: ; preds = %36
%38 = call i32 @putc_wrap(i8 signext 126, i32 %2, i32* %5)
%39 = call i32 @putc_wrap(i8 signext 62, i32 %2, i32* %5)
br label %40
40: ; preds = %37, %36
ret void
}