#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 */
typedef int uint8_t;

/* Variables and functions */
int /*<<< orphan*/ logmsg(int, char *);
int /*<<< orphan*/ readRandomData(int *, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int strlen(char *);
bool randomHexStrCat(char *aString, int aByteLen) {
  uint8_t rnd[aByteLen];
  if (!readRandomData(rnd, aByteLen)) {
    logmsg(1, "Cannot generate randomized hex tag.\n");
    return false;
  }
  aString = aString + strlen(aString);
  for (int i = 0; i < aByteLen; i++) {
    sprintf(aString, "%02x", rnd[i]);
    aString += 2;
  }
  return true;
}


x86 assembly (clang, -O0):
<randomHexStrCat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
lea    0xf(,%rax,4),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%esi
call   1050 <readRandomData@plt>
cmp    $0x0,%eax
jne    11ab <randomHexStrCat+0x6b>
mov    $0x1,%edi
lea    0xe6d(%rip),%rsi
call   1040 <logmsg@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    1222 <randomHexStrCat+0xe2>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1214 <randomHexStrCat+0xd4>
mov    -0x38(%rbp),%rax
mov    -0x10(%rbp),%rdi
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe30(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x10(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x10(%rbp)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11d3 <randomHexStrCat+0x93>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randomHexStrCat>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r12d
mov    %rdi,%r14
mov    %esi,%r13d
mov    %rsp,%rbx
lea    0xf(,%r13,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
call   1050 <readRandomData@plt>
test   %eax,%eax
je     11c0 <randomHexStrCat+0x80>
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    $0x1,%ecx
test   %r12d,%r12d
jle    11d3 <randomHexStrCat+0x93>
cltq
add    %rax,%r14
add    %r13,%r13
xor    %r15d,%r15d
lea    0xe89(%rip),%r12
nopl   0x0(%rax)
lea    (%r14,%r15,1),%rdi
mov    (%rbx,%r15,2),%edx
mov    %r12,%rsi
call   1060 <sprintf@plt>
add    $0x2,%r15
cmp    %r15,%r13
jne    11a0 <randomHexStrCat+0x60>
mov    $0x1,%ecx
jmp    11d3 <randomHexStrCat+0x93>
lea    0xe39(%rip),%rsi
mov    $0x1,%edi
call   1040 <logmsg@plt>
xor    %ecx,%ecx
mov    %ecx,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [37 x i8] c"Cannot generate randomized hex tag.\0A\00"
@.str.1 = [5 x i8] c"%02x\00"
define i32 @randomHexStrCat(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%10 = load i32, i32* %5
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %6
%13 = alloca i32, i64 %11
store i64 %11, i64* %7
%14 = load i32, i32* %5
%15 = call i32 @readRandomData(i32* %13, i32 %14)
%16 = icmp ne i32 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %2
%18 = call i32 @logmsg(i32 1, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
store i32 1, i32* %8
br label %42
19: ; preds = %2
%20 = load i8*, i8** %4
%21 = load i8*, i8** %4
%22 = call i32 @strlen(i8* %21)
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %20, i64 %23
store i8* %24, i8** %4
store i32 0, i32* %9
br label %25
25: ; preds = %38, %19
%26 = load i32, i32* %9
%27 = load i32, i32* %5
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %41
29: ; preds = %25
%30 = load i8*, i8** %4
%31 = load i32, i32* %9
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %13, i64 %32
%34 = load i32, i32* %33
%35 = call i32 @sprintf(i8* %30, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %34)
%36 = load i8*, i8** %4
%37 = getelementptr inbounds i8, i8* %36, i64 2
store i8* %37, i8** %4
br label %38
38: ; preds = %29
%39 = load i32, i32* %9
%40 = add nsw i32 %39, 1
store i32 %40, i32* %9
br label %25
41: ; preds = %25
store i32 1, i32* %3
store i32 1, i32* %8
br label %42
42: ; preds = %41, %17
%43 = load i8*, i8** %6
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
@.str = [37 x i8] c"Cannot generate randomized hex tag.\0A\00"
@.str.1 = [5 x i8] c"%02x\00"
define i32 @randomHexStrCat(i8* %0, i32 %1) {
%3 = zext i32 %1 to i64
%4 = alloca i32, i64 %3
%5 = call i32 @readRandomData(i32* %4, i32 %1)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = call i32 @logmsg(i32 1, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
br label %24
9: ; preds = %2
%10 = call i32 @strlen(i8* %0)
%11 = icmp sgt i32 %1, 0
br i1 %11, label %12, label %24
12: ; preds = %9
%13 = sext i32 %10 to i64
%14 = getelementptr inbounds i8, i8* %0, i64 %13
br label %15
15: ; preds = %12, %15
%16 = phi i64 [ 0, %12 ], [ %22, %15 ]
%17 = phi i8* [ %14, %12 ], [ %21, %15 ]
%18 = getelementptr inbounds i32, i32* %4, i64 %16
%19 = load i32, i32* %18
%20 = call i32 @sprintf(i8* dereferenceable(1) %17, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%21 = getelementptr inbounds i8, i8* %17, i64 2
%22 = add nuw nsw i64 %16, 1
%23 = icmp eq i64 %22, %3
br i1 %23, label %24, label %15
24: ; preds = %15, %9, %7
%25 = phi i32 [ 0, %7 ], [ 1, %9 ], [ 1, %15 ]
ret i32 %25
}