#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*/ buffer;
typedef int /*<<< orphan*/ bin;

/* Variables and functions */
int /*<<< orphan*/ intAsBinary(char *, unsigned int, int);
size_t makeByteArray(unsigned char *, char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char const *);
void make7BitString(unsigned char *compressed, const char *text) {
  int len = strlen(text);
  char buffer[(7 * len) + 1];
  memset(buffer, 0, sizeof(buffer));
  for (int i = 0; i < len; i++) {
    char bin[14];
    memset(bin, 0, sizeof(bin));
    unsigned chInt = text[i];
    intAsBinary(bin, chInt, 7);
    strcat(buffer, (char *)bin);
  }
  int rem = strlen(buffer) % 8;
  for (int i = 0; i < rem; i++) {
    strcat(buffer, "0");
  }
  size_t byteC = makeByteArray(compressed, buffer, strlen(buffer));
  compressed[(int)byteC] = '\003';
}


x86 assembly (clang, -O0):
<make7BitString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%ecx
mov    %ecx,%eax
shl    $0x3,%eax
sub    %ecx,%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x58(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
mov    %eax,%edx
xor    %esi,%esi
call   1050 <memset@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1203 <make7BitString+0xb3>
lea    -0x3a(%rbp),%rdi
xor    %esi,%esi
mov    $0xe,%edx
call   1050 <memset@plt>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x40(%rbp)
lea    -0x3a(%rbp),%rdi
mov    -0x40(%rbp),%esi
mov    $0x7,%edx
call   1040 <intAsBinary@plt>
mov    -0x58(%rbp),%rdi
lea    -0x3a(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11ac <make7BitString+0x5c>
mov    -0x58(%rbp),%rdi
call   1030 <strlen@plt>
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %edx,-0x44(%rbp)
movl   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%eax
cmp    -0x44(%rbp),%eax
jge    1248 <make7BitString+0xf8>
mov    -0x58(%rbp),%rdi
lea    0xdcb(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    121e <make7BitString+0xce>
mov    -0x58(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    %rax,-0x60(%rbp)
call   1030 <strlen@plt>
mov    -0x60(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    %eax,%edx
call   1060 <makeByteArray@plt>
mov    %rax,-0x50(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x50(%rbp),%rcx
movslq %ecx,%rcx
movb   $0x3,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make7BitString>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r15
mov    %rdi,-0x30(%rbp)
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
lea    0x0(,%rbx,8),%edx
sub    %eax,%edx
add    $0x1,%edx
lea    0xf(%rdx),%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%r12
sub    %rax,%r12
mov    %r12,%rsp
mov    %r12,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
test   %ebx,%ebx
jle    11e5 <make7BitString+0x95>
mov    %ebx,%r13d
xor    %r14d,%r14d
lea    -0x3e(%rbp),%rbx
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xe,%edx
call   1050 <memset@plt>
movsbl (%r15,%r14,1),%esi
mov    %rbx,%rdi
mov    $0x7,%edx
call   1040 <intAsBinary@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1070 <strcat@plt>
add    $0x1,%r14
cmp    %r14,%r13
jne    11b0 <make7BitString+0x60>
mov    %r12,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
lea    0x7(%rbx),%eax
test   %ebx,%ebx
cmovns %ebx,%eax
and    $0xfffffff8,%eax
sub    %eax,%ebx
test   %ebx,%ebx
jle    1220 <make7BitString+0xd0>
lea    0xdf9(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r15,%rsi
call   1070 <strcat@plt>
add    $0xffffffff,%ebx
jne    1210 <make7BitString+0xc0>
mov    %r12,%rdi
call   1030 <strlen@plt>
mov    -0x30(%rbp),%rbx
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %eax,%edx
call   1060 <makeByteArray@plt>
cltq
movb   $0x3,(%rbx,%rax,1)
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"0\00"
define void @make7BitString(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca [14 x i8]
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i64
store i8* %0, i8** %3
store i8* %1, i8** %4
%14 = load i8*, i8** %4
%15 = call i32 @strlen(i8* %14)
store i32 %15, i32* %5
%16 = load i32, i32* %5
%17 = mul nsw i32 7, %16
%18 = add nsw i32 %17, 1
%19 = zext i32 %18 to i64
%20 = call i8* @llvm.stacksave()
store i8* %20, i8** %6
%21 = alloca i8, i64 %19
store i64 %19, i64* %7
%22 = trunc i64 %19 to i32
%23 = call i32 @memset(i8* %21, i32 0, i32 %22)
store i32 0, i32* %8
br label %24
24: ; preds = %42, %2
%25 = load i32, i32* %8
%26 = load i32, i32* %5
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %45
28: ; preds = %24
%29 = getelementptr inbounds [14 x i8], [14 x i8]* %9, i64 0, i64 0
%30 = call i32 @memset(i8* %29, i32 0, i32 14)
%31 = load i8*, i8** %4
%32 = load i32, i32* %8
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
store i32 %36, i32* %10
%37 = getelementptr inbounds [14 x i8], [14 x i8]* %9, i64 0, i64 0
%38 = load i32, i32* %10
%39 = call i32 @intAsBinary(i8* %37, i32 %38, i32 7)
%40 = getelementptr inbounds [14 x i8], [14 x i8]* %9, i64 0, i64 0
%41 = call i32 @strcat(i8* %21, i8* %40)
br label %42
42: ; preds = %28
%43 = load i32, i32* %8
%44 = add nsw i32 %43, 1
store i32 %44, i32* %8
br label %24
45: ; preds = %24
%46 = call i32 @strlen(i8* %21)
%47 = srem i32 %46, 8
store i32 %47, i32* %11
store i32 0, i32* %12
br label %48
48: ; preds = %54, %45
%49 = load i32, i32* %12
%50 = load i32, i32* %11
%51 = icmp slt i32 %49, %50
br i1 %51, label %52, label %57
52: ; preds = %48
%53 = call i32 @strcat(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %54
54: ; preds = %52
%55 = load i32, i32* %12
%56 = add nsw i32 %55, 1
store i32 %56, i32* %12
br label %48
57: ; preds = %48
%58 = load i8*, i8** %3
%59 = call i32 @strlen(i8* %21)
%60 = call i64 @makeByteArray(i8* %58, i8* %21, i32 %59)
store i64 %60, i64* %13
%61 = load i8*, i8** %3
%62 = load i64, i64* %13
%63 = trunc i64 %62 to i32
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i8, i8* %61, i64 %64
store i8 3, i8* %65
%66 = load i8*, i8** %6
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"0\00"
define void @make7BitString(i8* %0, i8* %1) {
%3 = alloca [14 x i8]
%4 = tail call i32 @strlen(i8* %1)
%5 = mul nsw i32 %4, 7
%6 = add nsw i32 %5, 1
%7 = zext i32 %6 to i64
%8 = alloca i8, i64 %7
%9 = call i32 @memset(i8* %8, i32 0, i32 %6)
%10 = icmp sgt i32 %4, 0
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = getelementptr inbounds [14 x i8], [14 x i8]* %3, i64 0, i64 0
%13 = zext i32 %4 to i64
br label %18
14: ; preds = %18, %2
%15 = call i32 @strlen(i8* %8)
%16 = srem i32 %15, 8
%17 = icmp sgt i32 %16, 0
br i1 %17, label %34, label %28
18: ; preds = %11, %18
%19 = phi i64 [ 0, %11 ], [ %26, %18 ]
%20 = call i32 @memset(i8* %12, i32 0, i32 14)
%21 = getelementptr inbounds i8, i8* %1, i64 %19
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = call i32 @intAsBinary(i8* %12, i32 %23, i32 7)
%25 = call i32 @strcat(i8* %8, i8* %12)
%26 = add nuw nsw i64 %19, 1
%27 = icmp eq i64 %26, %13
br i1 %27, label %14, label %18
28: ; preds = %34, %14
%29 = call i32 @strlen(i8* %8)
%30 = call i64 @makeByteArray(i8* %0, i8* %8, i32 %29)
%31 = shl i64 %30, 32
%32 = ashr exact i64 %31, 32
%33 = getelementptr inbounds i8, i8* %0, i64 %32
store i8 3, i8* %33
ret void
34: ; preds = %14, %34
%35 = phi i32 [ %37, %34 ], [ 0, %14 ]
%36 = call i32 @strcat(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%37 = add nuw nsw i32 %35, 1
%38 = icmp eq i32 %37, %16
br i1 %38, label %28, label %34
}