#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*/ FILE;

/* Variables and functions */
int EOF;
int /*<<< orphan*/ encode_tuple(unsigned long, 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;
  unsigned long tuple = 0;
  if (delims) {
    putc_wrap('<', wrap, &len);
    putc_wrap('~', wrap, &len);
  }
  for (;;) {
    c = getc(fp);
    if (c != EOF) {
      tuple |= 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)
movq   $0x0,-0x28(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1187 <ascii85_encode+0x57>
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    118c <ascii85_encode+0x5c>
mov    -0x8(%rbp),%rdi
call   1050 <getc@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    0x2e46(%rip),%rcx
cmp    (%rcx),%eax
je     11e2 <ascii85_encode+0xb2>
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
cltq
or     -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x4,-0x1c(%rbp)
jge    11dd <ascii85_encode+0xad>
jmp    118c <ascii85_encode+0x5c>
jmp    11f6 <ascii85_encode+0xc6>
cmpl   $0x0,-0x1c(%rbp)
jne    11f1 <ascii85_encode+0xc1>
jmp    1238 <ascii85_encode+0x108>
jmp    11f6 <ascii85_encode+0xc6>
mov    -0x28(%rbp),%rdi
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    0x2dd1(%rip),%rcx
cmp    (%rcx),%eax
jne    1224 <ascii85_encode+0xf4>
jmp    1238 <ascii85_encode+0x108>
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
jmp    118c <ascii85_encode+0x5c>
cmpl   $0x0,-0xc(%rbp)
je     1264 <ascii85_encode+0x134>
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    %r12d,%r12d
jmp    11af <ascii85_encode+0x7f>
nopl   0x0(%rax,%rax,1)
lea    0x0(,%rbx,8),%eax
mov    $0x18,%cl
sub    %al,%cl
mov    %r14d,%eax
shl    %cl,%eax
lea    0x1(%rbx),%ecx
cltq
or     %rax,%r12
cmp    $0x3,%ebx
mov    %ecx,%ebx
jge    11c3 <ascii85_encode+0x93>
mov    %rbp,%rdi
call   1050 <getc@plt>
mov    %eax,%r14d
cmp    (%r15),%eax
jne    1190 <ascii85_encode+0x60>
test   %ebx,%ebx
je     11e7 <ascii85_encode+0xb7>
mov    %r12,%rdi
mov    %ebx,%esi
mov    %r13d,%edx
lea    0xc(%rsp),%rcx
mov    0x14(%rsp),%r8d
call   1040 <encode_tuple@plt>
xor    %ebx,%ebx
mov    $0x0,%r12d
cmp    (%r15),%r14d
jne    11af <ascii85_encode+0x7f>
cmpl   $0x0,0x10(%rsp)
je     1213 <ascii85_encode+0xe3>
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 i64
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 i64 0, i64* %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 = %56, %39, %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 %41
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 = sext i32 %33 to i64
%35 = load i64, i64* %12
%36 = or i64 %35, %34
store i64 %36, i64* %12
%37 = load i32, i32* %10
%38 = icmp slt i32 %37, 4
br i1 %38, label %39, label %40
39: ; preds = %27
br label %21
40: ; preds = %27
br label %46
41: ; preds = %21
%42 = load i32, i32* %10
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %41
br label %57
45: ; preds = %41
br label %46
46: ; preds = %45, %40
%47 = load i64, i64* %12
%48 = load i32, i32* %10
%49 = load i32, i32* %7
%50 = load i32, i32* %8
%51 = call i32 @encode_tuple(i64 %47, i32 %48, i32 %49, i32* %11, i32 %50)
%52 = load i32, i32* %9
%53 = load i32, i32* @EOF
%54 = icmp eq i32 %52, %53
br i1 %54, label %55, label %56
55: ; preds = %46
br label %57
56: ; preds = %46
store i64 0, i64* %12
store i32 0, i32* %10
br label %21
57: ; preds = %55, %44
%58 = load i32, i32* %6
%59 = icmp ne i32 %58, 0
br i1 %59, label %60, label %65
60: ; preds = %57
%61 = load i32, i32* %7
%62 = call i32 @putc_wrap(i8 signext 126, i32 %61, i32* %11)
%63 = load i32, i32* %7
%64 = call i32 @putc_wrap(i8 signext 62, i32 %63, i32* %11)
br label %65
65: ; preds = %60, %57
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 = %26, %11
%13 = phi i32 [ 0, %11 ], [ %27, %26 ]
%14 = phi i64 [ 0, %11 ], [ %28, %26 ]
%15 = call i32 @getc(i32* %0)
%16 = load i32, i32* @EOF
%17 = icmp eq i32 %15, %16
br i1 %17, label %29, 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 = sext i32 %22 to i64
%24 = or i64 %14, %23
%25 = icmp slt i32 %13, 3
br i1 %25, label %26, label %31
26: ; preds = %18, %31
%27 = phi i32 [ %19, %18 ], [ 0, %31 ]
%28 = phi i64 [ %24, %18 ], [ 0, %31 ]
br label %12
29: ; preds = %12
%30 = icmp eq i32 %13, 0
br i1 %30, label %37, label %31
31: ; preds = %29, %18
%32 = phi i32 [ %19, %18 ], [ %13, %29 ]
%33 = phi i64 [ %24, %18 ], [ %14, %29 ]
%34 = call i32 @encode_tuple(i64 %33, i32 %32, i32 %2, i32* %5, i32 %3)
%35 = load i32, i32* @EOF
%36 = icmp eq i32 %15, %35
br i1 %36, label %37, label %26
37: ; preds = %31, %29
br i1 %7, label %41, label %38
38: ; preds = %37
%39 = call i32 @putc_wrap(i8 signext 126, i32 %2, i32* %5)
%40 = call i32 @putc_wrap(i8 signext 62, i32 %2, i32* %5)
br label %41
41: ; preds = %38, %37
ret void
}