#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 */
char *malloc(int);
char *realloc(char *, size_t);
int /*<<< orphan*/ sprintf(char *, char *, ...);
unsigned short strlen(char const *);
char *pshexstr(const char *in) {
  char *out = malloc((3 * strlen(in) + 3) * sizeof(char));
  unsigned short count = 1, i;
  char *hex = out;
  hex += sprintf(hex, "<");
  for (i = 0; i < strlen(in); i++) {
    if (count >= 72) {
      hex += sprintf(hex, "\n");
      count = 0;
    }
    if (count == 0) {
      hex += sprintf(hex, " ");
      count++;
    }
    hex += sprintf(hex, "%02X", in[i]);
    count++;
    count++;
  }
  hex += sprintf(hex, ">");
  hex++;
  out = realloc(out, (size_t)(hex - out) * sizeof(*out));
  return out;
}


x86 assembly (clang, -O0):
<pshexstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
movzwl %ax,%eax
imul   $0x3,%eax,%eax
add    $0x3,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
movw   $0x1,-0x12(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe78(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
movw   $0x0,-0x14(%rbp)
movzwl -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %ax,%cx
mov    -0x24(%rbp),%eax
movzwl %cx,%ecx
cmp    %ecx,%eax
jge    128d <pshexstr+0x14d>
movzwl -0x12(%rbp),%eax
cmp    $0x48,%eax
jl     11fb <pshexstr+0xbb>
mov    -0x20(%rbp),%rdi
lea    0xe24(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
movw   $0x0,-0x12(%rbp)
movzwl -0x12(%rbp),%eax
cmp    $0x0,%eax
jne    1236 <pshexstr+0xf6>
mov    -0x20(%rbp),%rdi
lea    0xdf1(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x12(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x12(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rax
movzwl -0x14(%rbp),%ecx
movsbl (%rax,%rcx,1),%edx
lea    0xdb9(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x12(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x12(%rbp)
mov    -0x12(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x12(%rbp)
mov    -0x14(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x14(%rbp)
jmp    11a5 <pshexstr+0x65>
mov    -0x20(%rbp),%rdi
lea    0xd73(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rax
sub    %rax,%rsi
shl    $0x0,%rsi
call   1050 <realloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pshexstr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
call   1030 <strlen@plt>
movzwl %ax,%eax
lea    (%rax,%rax,2),%edi
add    $0x3,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
movw   $0x3c,(%rax)
lea    0x1(%rax),%r13
mov    %r15,%rdi
call   1030 <strlen@plt>
test   %ax,%ax
je     11dc <pshexstr+0x9c>
mov    $0x1,%bp
lea    0xe7b(%rip),%r12
xor    %ebx,%ebx
jmp    11be <pshexstr+0x7e>
nopl   0x0(%rax)
movsbl (%r15,%rbx,1),%edx
mov    %r13,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1060 <sprintf@plt>
cltq
add    %rax,%r13
add    $0x2,%ebp
add    $0x1,%rbx
mov    %r15,%rdi
call   1030 <strlen@plt>
movzwl %ax,%eax
cmp    %rax,%rbx
jae    11dc <pshexstr+0x9c>
cmp    $0x48,%bp
jb     1190 <pshexstr+0x50>
movw   $0xa,0x0(%r13)
movw   $0x20,0x1(%r13)
add    $0x2,%r13
mov    $0x1,%bp
jmp    1190 <pshexstr+0x50>
movw   $0x3e,0x0(%r13)
sub    %r14,%r13
add    $0x2,%r13
mov    %r14,%rdi
mov    %r13,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <realloc@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"<\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [5 x i8] c"%02X\00"
@.str.4 = [2 x i8] c">\00"
define i8* @pshexstr(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i16
%5 = alloca i16
%6 = alloca i8*
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call zeroext i16 @strlen(i8* %7)
%9 = zext i16 %8 to i32
%10 = mul nsw i32 3, %9
%11 = add nsw i32 %10, 3
%12 = sext i32 %11 to i64
%13 = mul i64 %12, 1
%14 = trunc i64 %13 to i32
%15 = call i8* @malloc(i32 %14)
store i8* %15, i8** %3
store i16 1, i16* %4
%16 = load i8*, i8** %3
store i8* %16, i8** %6
%17 = load i8*, i8** %6
%18 = call i32 (i8*, i8*, ...) @sprintf(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%19 = load i8*, i8** %6
%20 = sext i32 %18 to i64
%21 = getelementptr inbounds i8, i8* %19, i64 %20
store i8* %21, i8** %6
store i16 0, i16* %5
br label %22
22: ; preds = %67, %1
%23 = load i16, i16* %5
%24 = zext i16 %23 to i32
%25 = load i8*, i8** %2
%26 = call zeroext i16 @strlen(i8* %25)
%27 = zext i16 %26 to i32
%28 = icmp slt i32 %24, %27
br i1 %28, label %29, label %70
29: ; preds = %22
%30 = load i16, i16* %4
%31 = zext i16 %30 to i32
%32 = icmp sge i32 %31, 72
br i1 %32, label %33, label %39
33: ; preds = %29
%34 = load i8*, i8** %6
%35 = call i32 (i8*, i8*, ...) @sprintf(i8* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%36 = load i8*, i8** %6
%37 = sext i32 %35 to i64
%38 = getelementptr inbounds i8, i8* %36, i64 %37
store i8* %38, i8** %6
store i16 0, i16* %4
br label %39
39: ; preds = %33, %29
%40 = load i16, i16* %4
%41 = zext i16 %40 to i32
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %51
43: ; preds = %39
%44 = load i8*, i8** %6
%45 = call i32 (i8*, i8*, ...) @sprintf(i8* %44, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%46 = load i8*, i8** %6
%47 = sext i32 %45 to i64
%48 = getelementptr inbounds i8, i8* %46, i64 %47
store i8* %48, i8** %6
%49 = load i16, i16* %4
%50 = add i16 %49, 1
store i16 %50, i16* %4
br label %51
51: ; preds = %43, %39
%52 = load i8*, i8** %6
%53 = load i8*, i8** %2
%54 = load i16, i16* %5
%55 = zext i16 %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*, i8*, ...) @sprintf(i8* %52, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %58)
%60 = load i8*, i8** %6
%61 = sext i32 %59 to i64
%62 = getelementptr inbounds i8, i8* %60, i64 %61
store i8* %62, i8** %6
%63 = load i16, i16* %4
%64 = add i16 %63, 1
store i16 %64, i16* %4
%65 = load i16, i16* %4
%66 = add i16 %65, 1
store i16 %66, i16* %4
br label %67
67: ; preds = %51
%68 = load i16, i16* %5
%69 = add i16 %68, 1
store i16 %69, i16* %5
br label %22
70: ; preds = %22
%71 = load i8*, i8** %6
%72 = call i32 (i8*, i8*, ...) @sprintf(i8* %71, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%73 = load i8*, i8** %6
%74 = sext i32 %72 to i64
%75 = getelementptr inbounds i8, i8* %73, i64 %74
store i8* %75, i8** %6
%76 = load i8*, i8** %6
%77 = getelementptr inbounds i8, i8* %76, i32 1
store i8* %77, i8** %6
%78 = load i8*, i8** %3
%79 = load i8*, i8** %6
%80 = load i8*, i8** %3
%81 = ptrtoint i8* %79 to i64
%82 = ptrtoint i8* %80 to i64
%83 = sub i64 %81, %82
%84 = mul i64 %83, 1
%85 = call i8* @realloc(i8* %78, i64 %84)
store i8* %85, i8** %3
%86 = load i8*, i8** %3
ret i8* %86
}

LLVM IR (-O2):
@.str.3 = [5 x i8] c"%02X\00"
define noalias i8* @pshexstr(i8* %0) {
%2 = tail call zeroext i16 @strlen(i8* %0)
%3 = zext i16 %2 to i32
%4 = mul nuw nsw i32 %3, 3
%5 = add nuw nsw i32 %4, 3
%6 = tail call i8* @malloc(i32 %5)
%7 = bitcast i8* %6 to i16*
store i16 60, i16* %7
%8 = getelementptr inbounds i8, i8* %6, i64 1
%9 = tail call zeroext i16 @strlen(i8* %0)
%10 = icmp eq i16 %9, 0
br i1 %10, label %35, label %11
11: ; preds = %1, %21
%12 = phi i64 [ %31, %21 ], [ 0, %1 ]
%13 = phi i8* [ %29, %21 ], [ %8, %1 ]
%14 = phi i16 [ %30, %21 ], [ 1, %1 ]
%15 = icmp ugt i16 %14, 71
br i1 %15, label %16, label %21
16: ; preds = %11
%17 = bitcast i8* %13 to i16*
store i16 10, i16* %17
%18 = getelementptr inbounds i8, i8* %13, i64 1
%19 = bitcast i8* %18 to i16*
store i16 32, i16* %19
%20 = getelementptr inbounds i8, i8* %13, i64 2
br label %21
21: ; preds = %11, %16
%22 = phi i16 [ 1, %16 ], [ %14, %11 ]
%23 = phi i8* [ %20, %16 ], [ %13, %11 ]
%24 = getelementptr inbounds i8, i8* %0, i64 %12
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %23, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %26)
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %23, i64 %28
%30 = add nuw nsw i16 %22, 2
%31 = add nuw nsw i64 %12, 1
%32 = tail call zeroext i16 @strlen(i8* %0)
%33 = zext i16 %32 to i64
%34 = icmp ult i64 %31, %33
br i1 %34, label %11, label %35
35: ; preds = %21, %1
%36 = phi i8* [ %8, %1 ], [ %29, %21 ]
%37 = bitcast i8* %36 to i16*
store i16 62, i16* %37
%38 = getelementptr inbounds i8, i8* %36, i64 2
%39 = ptrtoint i8* %38 to i64
%40 = ptrtoint i8* %6 to i64
%41 = sub i64 %39, %40
%42 = tail call i8* @realloc(i8* %6, i64 %41)
ret i8* %42
}