#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*/ sprintf(char *, char *, unsigned char);
size_t strlen(char *);
void oap_hex_add_to_str(char *str, char *buf, int len) {
  int j;
  char str2[3];
  for (j = 0; j < len; j++) {
    sprintf(str2, "%02X", (unsigned char)buf[j]);
    str[strlen(str) + 1] = 0;
    str[strlen(str)] = str2[0];
    str[strlen(str) + 1] = 0;
    str[strlen(str)] = str2[1];
    str[strlen(str) + 1] = 0;
    str[strlen(str)] = str2[2];
  }
}


x86 assembly (clang, -O0):
<oap_hex_add_to_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1233 <oap_hex_add_to_str+0x113>
lea    -0x1b(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
lea    0xea7(%rip),%rsi
movzbl (%rax,%rcx,1),%edx
call   1040 <sprintf@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x68(%rbp),%rax
movb   $0x0,0x1(%rax,%rcx,1)
mov    -0x1b(%rbp),%al
mov    %al,-0x59(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x59(%rbp),%dl
mov    %rax,%rcx
mov    -0x58(%rbp),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
movb   $0x0,0x1(%rax,%rcx,1)
mov    -0x1a(%rbp),%al
mov    %al,-0x41(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x41(%rbp),%dl
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
movb   $0x0,0x1(%rax,%rcx,1)
mov    -0x19(%rbp),%al
mov    %al,-0x29(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x29(%rbp),%dl
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    113a <oap_hex_add_to_str+0x1a>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<oap_hex_add_to_str>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
jle    11ca <oap_hex_add_to_str+0xaa>
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %edx,%r13d
xor    %ebp,%ebp
lea    0x5(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl (%r14,%rbp,1),%edx
mov    %r12,%rdi
lea    0xea1(%rip),%rsi
call   1040 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
movb   $0x0,0x1(%rax,%rbx,1)
movzbl 0x5(%rsp),%r15d
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %r15b,(%rbx,%rax,1)
mov    %rbx,%rdi
call   1030 <strlen@plt>
movb   $0x0,0x1(%rax,%rbx,1)
movzbl 0x6(%rsp),%r15d
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %r15b,(%rbx,%rax,1)
mov    %rbx,%rdi
call   1030 <strlen@plt>
movb   $0x0,0x1(%rax,%rbx,1)
movzbl 0x7(%rsp),%r15d
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %r15b,(%rbx,%rax,1)
add    $0x1,%rbp
cmp    %rbp,%r13
jne    1150 <oap_hex_add_to_str+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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