#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 rand();
void __peinfect_random_sectionname(char *mem, size_t memsize) {
  size_t rnd;
  if (mem == NULL || memsize == 0) {
    return;
  }
  mem[0] = '.';
  while (--memsize != 0) {
    rnd = rand() % 3;
    if (rnd == 1) {
      mem[memsize] = 0x30 + rand() % 10;
    } else if (rnd == 2) {
      mem[memsize] = 0x41 + rand() % 26;
    } else {
      mem[memsize] = 0x61 + rand() % 26;
    }
  }
}


x86 assembly (clang, -O0):
<__peinfect_random_sectionname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1136 <__peinfect_random_sectionname+0x26>
cmpq   $0x0,-0x10(%rbp)
jne    113b <__peinfect_random_sectionname+0x2b>
jmp    11ef <__peinfect_random_sectionname+0xdf>
mov    -0x8(%rbp),%rax
movb   $0x2e,(%rax)
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     11ef <__peinfect_random_sectionname+0xdf>
mov    $0x0,%al
call   1030 <rand@plt>
mov    $0x3,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x1,-0x18(%rbp)
jne    119b <__peinfect_random_sectionname+0x8b>
mov    $0x0,%al
call   1030 <rand@plt>
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%edx
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    11ea <__peinfect_random_sectionname+0xda>
cmpq   $0x2,-0x18(%rbp)
jne    11c8 <__peinfect_random_sectionname+0xb8>
mov    $0x0,%al
call   1030 <rand@plt>
mov    $0x1a,%ecx
cltd
idiv   %ecx
add    $0x41,%edx
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    11e5 <__peinfect_random_sectionname+0xd5>
mov    $0x0,%al
call   1030 <rand@plt>
mov    $0x1a,%ecx
cltd
idiv   %ecx
add    $0x61,%edx
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    11ea <__peinfect_random_sectionname+0xda>
jmp    1142 <__peinfect_random_sectionname+0x32>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__peinfect_random_sectionname>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     118a <__peinfect_random_sectionname+0x7a>
mov    %rsi,%rbx
test   %rsi,%rsi
je     118a <__peinfect_random_sectionname+0x7a>
mov    %rdi,%r14
movb   $0x2e,(%rdi)
jmp    1149 <__peinfect_random_sectionname+0x39>
nopl   0x0(%rax)
mov    $0x61,%r15b
mov    $0x1a,%ebp
xor    %eax,%eax
call   1030 <rand@plt>
cltd
idiv   %ebp
add    %r15b,%dl
mov    %dl,(%r14,%rbx,1)
add    $0xffffffffffffffff,%rbx
je     118a <__peinfect_random_sectionname+0x7a>
xor    %eax,%eax
call   1030 <rand@plt>
cltq
imul   $0x55555556,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,2),%ecx
sub    %ecx,%eax
cmp    $0x1,%eax
je     1180 <__peinfect_random_sectionname+0x70>
cmp    $0x2,%eax
jne    1130 <__peinfect_random_sectionname+0x20>
mov    $0x41,%r15b
jmp    1133 <__peinfect_random_sectionname+0x23>
mov    $0x30,%r15b
mov    $0xa,%ebp
jmp    1138 <__peinfect_random_sectionname+0x28>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @__peinfect_random_sectionname(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
store i8* %0, i8** %3
store i64 %1, i64* %4
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, null
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = load i64, i64* %4
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %8, %2
br label %54
12: ; preds = %8
%13 = load i8*, i8** %3
%14 = getelementptr inbounds i8, i8* %13, i64 0
store i8 46, i8* %14
br label %15
15: ; preds = %53, %12
%16 = load i64, i64* %4
%17 = add i64 %16, -1
store i64 %17, i64* %4
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %54
19: ; preds = %15
%20 = call i32 (...) @rand()
%21 = srem i32 %20, 3
%22 = sext i32 %21 to i64
store i64 %22, i64* %5
%23 = load i64, i64* %5
%24 = icmp eq i64 %23, 1
br i1 %24, label %25, label %33
25: ; preds = %19
%26 = call i32 (...) @rand()
%27 = srem i32 %26, 10
%28 = add nsw i32 48, %27
%29 = trunc i32 %28 to i8
%30 = load i8*, i8** %3
%31 = load i64, i64* %4
%32 = getelementptr inbounds i8, i8* %30, i64 %31
store i8 %29, i8* %32
br label %53
33: ; preds = %19
%34 = load i64, i64* %5
%35 = icmp eq i64 %34, 2
br i1 %35, label %36, label %44
36: ; preds = %33
%37 = call i32 (...) @rand()
%38 = srem i32 %37, 26
%39 = add nsw i32 65, %38
%40 = trunc i32 %39 to i8
%41 = load i8*, i8** %3
%42 = load i64, i64* %4
%43 = getelementptr inbounds i8, i8* %41, i64 %42
store i8 %40, i8* %43
br label %52
44: ; preds = %33
%45 = call i32 (...) @rand()
%46 = srem i32 %45, 26
%47 = add nsw i32 97, %46
%48 = trunc i32 %47 to i8
%49 = load i8*, i8** %3
%50 = load i64, i64* %4
%51 = getelementptr inbounds i8, i8* %49, i64 %50
store i8 %48, i8* %51
br label %52
52: ; preds = %44, %36
br label %53
53: ; preds = %52, %25
br label %15
54: ; preds = %11, %15
ret void
}

LLVM IR (-O2):
define void @__peinfect_random_sectionname(i8* writeonly %0, i64 %1) {
%3 = icmp eq i8* %0, null
%4 = icmp eq i64 %1, 0
%5 = or i1 %3, %4
br i1 %5, label %25, label %6
6: ; preds = %2
store i8 46, i8* %0
%7 = add i64 %1, -1
%8 = icmp eq i64 %7, 0
br i1 %8, label %25, label %9
9: ; preds = %6, %15
%10 = phi i64 [ %23, %15 ], [ %7, %6 ]
%11 = tail call i32 (...) @rand()
%12 = srem i32 %11, 3
switch i32 %12, label %14 [
i32 1, label %15
i32 2, label %13
]
13: ; preds = %9
br label %15
14: ; preds = %9
br label %15
15: ; preds = %9, %13, %14
%16 = phi i32 [ 26, %13 ], [ 26, %14 ], [ 10, %9 ]
%17 = phi i8 [ 65, %13 ], [ 97, %14 ], [ 48, %9 ]
%18 = tail call i32 (...) @rand()
%19 = srem i32 %18, %16
%20 = trunc i32 %19 to i8
%21 = add nsw i8 %17, %20
%22 = getelementptr inbounds i8, i8* %0, i64 %10
store i8 %21, i8* %22
%23 = add i64 %10, -1
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %9
25: ; preds = %15, %6, %2
ret void
}