#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*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char const *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char const);
int strlen(char const *);
void print_ustr_bytes(const char str[]) {
  int strLen = strlen(str);
  char *strBuf = malloc(strLen * 4);
  for (int i = 0; i <= strLen; i++) {
    sprintf(&strBuf[i * 4], "\\x%02X", str[i]);
  }
  printf("String: '%s' -> Bytes: '%s'\n", str, strBuf);
  memset(strBuf, 0, strLen * 4);
  free(strBuf);
}


x86 assembly (clang, -O0):
<print_ustr_bytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
shl    $0x2,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     11cf <print_ustr_bytes+0x6f>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%eax
shl    $0x2,%eax
cltq
add    %rax,%rdi
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
lea    0xe48(%rip),%rsi
movsbl (%rax,%rcx,1),%edx
call   1080 <sprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    118e <print_ustr_bytes+0x2e>
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe29(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%edx
shl    $0x2,%edx
xor    %esi,%esi
call   1060 <memset@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_ustr_bytes>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r13
call   1040 <strlen@plt>
mov    %eax,%ebp
lea    0x0(,%rbp,4),%edi
mov    %edi,0x4(%rsp)
call   1070 <malloc@plt>
mov    %rax,%r15
test   %ebp,%ebp
js     11be <print_ustr_bytes+0x5e>
add    $0x1,%ebp
xor    %r14d,%r14d
lea    0xe67(%rip),%r12
mov    %r15,%rbx
nopl   0x0(%rax)
movsbl 0x0(%r13,%r14,1),%edx
mov    %rbx,%rdi
mov    %r12,%rsi
call   1080 <sprintf@plt>
add    $0x1,%r14
add    $0x4,%rbx
cmp    %r14,%rbp
jne    11a0 <print_ustr_bytes+0x40>
lea    0xe42(%rip),%rdi
mov    %r13,%rsi
mov    %r15,%rdx
call   1050 <printf@plt>
mov    %r15,%rdi
xor    %esi,%esi
mov    0x4(%rsp),%edx
call   1060 <memset@plt>
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"\\x%02X\00"
@.str.1 = [29 x i8] c"String: '%s' -> Bytes: '%s'\0A\00"
define void @print_ustr_bytes(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @strlen(i8* %6)
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = mul nsw i32 %8, 4
%10 = call i8* @malloc(i32 %9)
store i8* %10, i8** %4
store i32 0, i32* %5
br label %11
11: ; preds = %27, %1
%12 = load i32, i32* %5
%13 = load i32, i32* %3
%14 = icmp sle i32 %12, %13
br i1 %14, label %15, label %30
15: ; preds = %11
%16 = load i8*, i8** %4
%17 = load i32, i32* %5
%18 = mul nsw i32 %17, 4
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %16, i64 %19
%21 = load i8*, i8** %2
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8, i8* %24
%26 = call i32 @sprintf(i8* %20, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8 signext %25)
br label %27
27: ; preds = %15
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 1
store i32 %29, i32* %5
br label %11
30: ; preds = %11
%31 = load i8*, i8** %2
%32 = load i8*, i8** %4
%33 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %31, i8* %32)
%34 = load i8*, i8** %4
%35 = load i32, i32* %3
%36 = mul nsw i32 %35, 4
%37 = call i32 @memset(i8* %34, i32 0, i32 %36)
%38 = load i8*, i8** %4
%39 = call i32 @free(i8* %38)
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"\\x%02X\00"
@.str.1 = [29 x i8] c"String: '%s' -> Bytes: '%s'\0A\00"
define void @print_ustr_bytes(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = shl nsw i32 %2, 2
%4 = tail call i8* @malloc(i32 %3)
%5 = icmp slt i32 %2, 0
br i1 %5, label %9, label %6
6: ; preds = %1
%7 = add nuw i32 %2, 1
%8 = zext i32 %7 to i64
br label %13
9: ; preds = %13, %1
%10 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %4)
%11 = tail call i32 @memset(i8* %4, i32 0, i32 %3)
%12 = tail call i32 @free(i8* %4)
ret void
13: ; preds = %6, %13
%14 = phi i64 [ 0, %6 ], [ %20, %13 ]
%15 = shl nsw i64 %14, 2
%16 = getelementptr inbounds i8, i8* %4, i64 %15
%17 = getelementptr inbounds i8, i8* %0, i64 %14
%18 = load i8, i8* %17
%19 = tail call i32 @sprintf(i8* dereferenceable(1) %16, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8 signext %18)
%20 = add nuw nsw i64 %14, 1
%21 = icmp eq i64 %20, %8
br i1 %21, label %9, label %13
}