#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*/ encode_single(char const, char **);
char *malloc(size_t);
int /*<<< orphan*/ strcat(char *, char *);
size_t strlen(char const *);
char *encode_bulk(char const *in) {
  char *buf[7];
  char *res;
  size_t len = strlen(in);
  res = malloc(len * 5 + 2);
  if (res == NULL) {
    return "";
  }
  for (unsigned int i = 0; i < len; i++) {
    encode_single(in[i], buf);
    strcat(res, *buf);
  }
  return res;
}


x86 assembly (clang, -O0):
<encode_bulk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x60(%rbp)
imul   $0x5,-0x60(%rbp),%rdi
add    $0x2,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jne    1186 <encode_bulk+0x46>
lea    0xe83(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11d3 <encode_bulk+0x93>
movl   $0x0,-0x64(%rbp)
mov    -0x64(%rbp),%eax
cmp    -0x60(%rbp),%rax
jae    11cb <encode_bulk+0x8b>
mov    -0x10(%rbp),%rax
mov    -0x64(%rbp),%ecx
mov    (%rax,%rcx,1),%al
lea    -0x50(%rbp),%rsi
movsbl %al,%edi
call   1040 <encode_single@plt>
mov    -0x58(%rbp),%rdi
mov    -0x50(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    118d <encode_bulk+0x4d>
mov    -0x58(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<encode_bulk>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x40,%rsp
mov    %rdi,%r14
call   1030 <strlen@plt>
mov    %rax,%r13
lea    (%rax,%rax,4),%rdi
add    $0x2,%rdi
call   1050 <malloc@plt>
test   %rax,%rax
je     11a3 <encode_bulk+0x63>
mov    %rax,%r15
test   %r13,%r13
je     11aa <encode_bulk+0x6a>
xor    %ebx,%ebx
mov    %rsp,%r12
nopw   0x0(%rax,%rax,1)
movsbl (%r14,%rbx,1),%edi
mov    %r12,%rsi
call   1040 <encode_single@plt>
mov    (%rsp),%rsi
mov    %r15,%rdi
call   1060 <strcat@plt>
add    $0x1,%ebx
cmp    %rbx,%r13
ja     1180 <encode_bulk+0x40>
jmp    11aa <encode_bulk+0x6a>
lea    0xe56(%rip),%r15
mov    %r15,%rax
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define i8* @encode_bulk(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca [7 x i8*]
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = call i64 @strlen(i8* %8)
store i64 %9, i64* %6
%10 = load i64, i64* %6
%11 = mul i64 %10, 5
%12 = add i64 %11, 2
%13 = call i8* @malloc(i64 %12)
store i8* %13, i8** %5
%14 = load i8*, i8** %5
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %17
16: ; preds = %1
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %2
br label %40
17: ; preds = %1
store i32 0, i32* %7
br label %18
18: ; preds = %35, %17
%19 = load i32, i32* %7
%20 = zext i32 %19 to i64
%21 = load i64, i64* %6
%22 = icmp ult i64 %20, %21
br i1 %22, label %23, label %38
23: ; preds = %18
%24 = load i8*, i8** %3
%25 = load i32, i32* %7
%26 = zext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i8, i8* %27
%29 = getelementptr inbounds [7 x i8*], [7 x i8*]* %4, i64 0, i64 0
%30 = call i32 @encode_single(i8 signext %28, i8** %29)
%31 = load i8*, i8** %5
%32 = getelementptr inbounds [7 x i8*], [7 x i8*]* %4, i64 0, i64 0
%33 = load i8*, i8** %32
%34 = call i32 @strcat(i8* %31, i8* %33)
br label %35
35: ; preds = %23
%36 = load i32, i32* %7
%37 = add i32 %36, 1
store i32 %37, i32* %7
br label %18
38: ; preds = %18
%39 = load i8*, i8** %5
store i8* %39, i8** %2
br label %40
40: ; preds = %38, %16
%41 = load i8*, i8** %2
ret i8* %41
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define i8* @encode_bulk(i8* nocapture %0) {
%2 = alloca [7 x i8*]
%3 = bitcast [7 x i8*]* %2 to i8*
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = mul i64 %4, 5
%6 = add i64 %5, 2
%7 = tail call i8* @malloc(i64 %6)
%8 = icmp eq i8* %7, null
br i1 %8, label %23, label %9
9: ; preds = %1
%10 = icmp eq i64 %4, 0
br i1 %10, label %23, label %11
11: ; preds = %9
%12 = getelementptr inbounds [7 x i8*], [7 x i8*]* %2, i64 0, i64 0
br label %13
13: ; preds = %11, %13
%14 = phi i64 [ 0, %11 ], [ %21, %13 ]
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = load i8, i8* %15
%17 = call i32 @encode_single(i8 signext %16, i8** %12)
%18 = load i8*, i8** %12
%19 = call i32 @strcat(i8* %7, i8* %18)
%20 = add nuw nsw i64 %14, 1
%21 = and i64 %20, 4294967295
%22 = icmp ugt i64 %4, %21
br i1 %22, label %13, label %23
23: ; preds = %13, %9, %1
%24 = phi i8* [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %1 ], [ %7, %9 ], [ %7, %13 ]
ret i8* %24
}