#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ pack2zone(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
int main(int argc, char *argv[]) {
  int i;
  char a[] = {0x35, 0xC8, 0x00};
  char *b = (char *)malloc(sizeof(char) * (2 * strlen(a)));
  memset(b, 0, strlen(a) + 1);
  pack2zone(a, b);
  printf("in:");
  for (i = 0; i < strlen(a); i++) {
    printf("%#x", (char)*(a + i));
  }
  printf(".\nout:");
  for (i = 0; i < (2 * strlen(a) - 1); i++) {
    printf("%#x", (char)*(b + i));
  }
  printf(".\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe93(%rip),%ax
mov    %ax,-0x17(%rbp)
mov    0xe8b(%rip),%al
mov    %al,-0x15(%rbp)
lea    -0x17(%rbp),%rdi
call   1040 <strlen@plt>
shl    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    -0x17(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%edx
add    $0x1,%edx
xor    %esi,%esi
call   1060 <memset@plt>
lea    -0x17(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <pack2zone@plt>
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
lea    -0x17(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
cmp    %ecx,%eax
jge    121b <main+0xcb>
movslq -0x14(%rbp),%rax
movsbl -0x17(%rbp,%rax,1),%esi
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11da <main+0x8a>
lea    0xde9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x30(%rbp)
lea    -0x17(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
shl    $0x1,%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    127a <main+0x12a>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xda2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1230 <main+0xe0>
lea    0xd91(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
movb   $0x0,0x6(%rsp)
movw   $0xc835,0x4(%rsp)
lea    0x4(%rsp),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    (%rax,%rax,1),%edi
call   1080 <malloc@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1070 <memset@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <pack2zone@plt>
lea    0xe50(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jle    1202 <main+0xa2>
lea    0xe3a(%rip),%r14
lea    0x4(%rsp),%r12
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl 0x4(%rsp,%rbx,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbx
mov    %r12,%rdi
call   1050 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     11e0 <main+0x80>
lea    0xe02(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x4(%rsp),%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jle    1257 <main+0xf7>
lea    0xde2(%rip),%r14
lea    0x4(%rsp),%r12
xor    %ebx,%ebx
nopl   0x0(%rax)
movsbl (%r15,%rbx,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbx
mov    %r12,%rdi
call   1050 <strlen@plt>
add    %eax,%eax
add    $0xffffffff,%eax
cltq
cmp    %rax,%rbx
jl     1230 <main+0xd0>
lea    0xdb4(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@__const.main.a = [3 x i8] c"5\C8\00"
@.str = [4 x i8] c"in:\00"
@.str.1 = [4 x i8] c"%#x\00"
@.str.2 = [7 x i8] c".\0Aout:\00"
@str = [2 x i8] c".\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [3 x i8]
%4 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%5 = call i32 @strlen(i8* %4)
%6 = shl nsw i32 %5, 1
%7 = call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to i8*
%9 = call i32 @strlen(i8* %4)
%10 = add nsw i32 %9, 1
%11 = call i32 @memset(i8* %8, i32 0, i32 %10)
%12 = call i32 @pack2zone(i8* %4, i8* %8)
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @strlen(i8* %4)
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %26
16: ; preds = %2, %16
%17 = phi i64 [ %22, %16 ], [ 0, %2 ]
%18 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = add nuw nsw i64 %17, 1
%23 = call i32 @strlen(i8* %4)
%24 = sext i32 %23 to i64
%25 = icmp slt i64 %22, %24
br i1 %25, label %16, label %26
26: ; preds = %16, %2
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%28 = call i32 @strlen(i8* %4)
%29 = icmp sgt i32 %28, 0
br i1 %29, label %30, label %42
30: ; preds = %26, %30
%31 = phi i64 [ %36, %30 ], [ 0, %26 ]
%32 = getelementptr inbounds i8, i8* %8, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %34)
%36 = add nuw nsw i64 %31, 1
%37 = call i32 @strlen(i8* %4)
%38 = shl nsw i32 %37, 1
%39 = add nsw i32 %38, -1
%40 = sext i32 %39 to i64
%41 = icmp slt i64 %36, %40
br i1 %41, label %30, label %42
42: ; preds = %30, %26
%43 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
ret i32 0
}