#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 */
int /*<<< orphan*/ encodeBase31(char *, int, int);
void encode_triple(char *result, int difx, int dify) {
  if (dify < 4 * 34) {
    encodeBase31(result, ((difx / 28) + 6 * (dify / 34)), 1);
    encodeBase31(result + 1, ((difx % 28) * 34 + (dify % 34)), 2);
  } else {
    encodeBase31(result, (difx / 24) + 24, 1);
    encodeBase31(result + 1, (difx % 24) * 40 + (dify - 136), 2);
  }
}


x86 assembly (clang, -O0):
<encode_triple>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpl   $0x88,-0x10(%rbp)
jge    118c <encode_triple+0x7c>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%eax
mov    $0x1c,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
mov    -0x10(%rbp),%eax
mov    $0x22,%ecx
cltd
idiv   %ecx
imul   $0x6,%eax,%eax
add    %eax,%esi
mov    $0x1,%edx
call   1030 <encodeBase31@plt>
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
mov    -0xc(%rbp),%eax
mov    $0x1c,%ecx
cltd
idiv   %ecx
imul   $0x22,%edx,%esi
mov    -0x10(%rbp),%eax
mov    $0x22,%ecx
cltd
idiv   %ecx
add    %edx,%esi
mov    $0x2,%edx
call   1030 <encodeBase31@plt>
jmp    11d4 <encode_triple+0xc4>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%eax
mov    $0x18,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
add    $0x18,%esi
mov    $0x1,%edx
call   1030 <encodeBase31@plt>
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
mov    -0xc(%rbp),%eax
mov    $0x18,%ecx
cltd
idiv   %ecx
imul   $0x28,%edx,%esi
mov    -0x10(%rbp),%eax
sub    $0x88,%eax
add    %eax,%esi
mov    $0x2,%edx
call   1030 <encodeBase31@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<encode_triple>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %edx,%r15d
mov    %esi,%r12d
mov    %rdi,%r14
cmp    $0x87,%edx
jg     11a3 <encode_triple+0x93>
movslq %r15d,%rax
imul   $0x78787879,%rax,%r13
mov    %r13,%rax
shr    $0x3f,%rax
sar    $0x24,%r13
add    %eax,%r13d
lea    0x0(%r13,%r13,2),%eax
movslq %r12d,%rcx
imul   $0xffffffff92492493,%rcx,%rbx
shr    $0x20,%rbx
add    %r12d,%ebx
mov    %ebx,%ecx
shr    $0x1f,%ecx
sar    $0x4,%ebx
add    %ecx,%ebx
lea    (%rbx,%rax,2),%esi
mov    %r14,%rdi
mov    $0x1,%edx
call   1030 <encodeBase31@plt>
add    $0x1,%r14
lea    (%rbx,%rbx,8),%eax
lea    (%rax,%rax,2),%eax
add    %ebx,%eax
sub    %eax,%r12d
mov    %r12d,%eax
shl    $0x5,%eax
lea    (%rax,%r12,2),%eax
mov    %r13d,%ecx
shl    $0x5,%ecx
lea    (%rcx,%r13,2),%ecx
sub    %ecx,%r15d
add    %eax,%r15d
mov    %r14,%rdi
mov    %r15d,%esi
jmp    11ed <encode_triple+0xdd>
movslq %r12d,%r12
imul   $0x2aaaaaab,%r12,%rbx
mov    %rbx,%r13
shr    $0x3f,%r13
sar    $0x22,%rbx
lea    (%rbx,%r13,1),%esi
add    $0x18,%esi
mov    %r14,%rdi
mov    $0x1,%edx
call   1030 <encodeBase31@plt>
add    $0x1,%r14
add    %r13d,%ebx
shl    $0x3,%ebx
lea    (%rbx,%rbx,2),%eax
sub    %eax,%r12d
lea    (%r12,%r12,4),%eax
lea    (%r15,%rax,8),%esi
add    $0xffffff78,%esi
mov    %r14,%rdi
mov    $0x2,%edx
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <encodeBase31@plt>

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

LLVM IR (-O2):
define void @encode_triple(i8* %0, i32 %1, i32 %2) {
%4 = icmp slt i32 %2, 136
br i1 %4, label %5, label %17
5: ; preds = %3
%6 = sdiv i32 %1, 28
%7 = sdiv i32 %2, 34
%8 = mul nsw i32 %7, 6
%9 = add nsw i32 %8, %6
%10 = tail call i32 @encodeBase31(i8* %0, i32 %9, i32 1)
%11 = getelementptr inbounds i8, i8* %0, i64 1
%12 = srem i32 %1, 28
%13 = mul nsw i32 %12, 34
%14 = srem i32 %2, 34
%15 = add nsw i32 %13, %14
%16 = tail call i32 @encodeBase31(i8* %11, i32 %15, i32 2)
br label %27
17: ; preds = %3
%18 = sdiv i32 %1, 24
%19 = add nsw i32 %18, 24
%20 = tail call i32 @encodeBase31(i8* %0, i32 %19, i32 1)
%21 = getelementptr inbounds i8, i8* %0, i64 1
%22 = srem i32 %1, 24
%23 = mul nsw i32 %22, 40
%24 = add nsw i32 %2, -136
%25 = add nsw i32 %24, %23
%26 = tail call i32 @encodeBase31(i8* %21, i32 %25, i32 2)
br label %27
27: ; preds = %17, %5
ret void
}