#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 scalar_t__ uint8_t;
typedef scalar_t__ uint64_t;
typedef scalar_t__ uint32_t;
typedef scalar_t__ uint16_t;

/* Variables and functions */
int /*<<< orphan*/ create_reverse_instruction(scalar_t__, unsigned int);
scalar_t__ is_address_referenced(void *);
int /*<<< orphan*/ printf(char *);
void reverse_code_generator(void *address, unsigned int size) {
  uint64_t value;
  printf("\n=== Reverse code generator ===\n");
  if (is_address_referenced(address)) {
    return;
  }
  value = 0;
  switch (size) {
  case 1:
    value = *((uint8_t *)address);
    break;
  case 2:
    value = *((uint16_t *)address);
    break;
  case 4:
    value = *((uint32_t *)address);
    break;
  case 8:
    value = *((uint64_t *)address);
    break;
  }
  create_reverse_instruction(value, size);
}


x86 assembly (clang, -O0):
<reverse_code_generator>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xeda(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1050 <is_address_referenced@plt>
cmp    $0x0,%rax
je     1163 <reverse_code_generator+0x33>
jmp    11db <reverse_code_generator+0xab>
movq   $0x0,-0x18(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x7,%eax
ja     11cf <reverse_code_generator+0x9f>
mov    -0x20(%rbp),%rax
lea    0xe75(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    11cf <reverse_code_generator+0x9f>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    11cf <reverse_code_generator+0x9f>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    11cf <reverse_code_generator+0x9f>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <create_reverse_instruction@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverse_code_generator>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xec1(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1050 <is_address_referenced@plt>
test   %rax,%rax
je     1158 <reverse_code_generator+0x28>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
xor    %edi,%edi
cmp    $0x8,%ebp
ja     116c <reverse_code_generator+0x3c>
mov    $0x116,%eax
bt     %ebp,%eax
jae    116c <reverse_code_generator+0x3c>
mov    (%rbx),%rdi
mov    %ebp,%esi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <create_reverse_instruction@plt>

LLVM IR (-O0):
@.str = [33 x i8] c"\0A=== Reverse code generator ===\0A\00"
define void @reverse_code_generator(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i64
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%7 = load i8*, i8** %3
%8 = call i64 @is_address_referenced(i8* %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %2
br label %33
11: ; preds = %2
store i64 0, i64* %5
%12 = load i32, i32* %4
switch i32 %12, label %29 [
i32 1, label %13
i32 2, label %17
i32 4, label %21
i32 8, label %25
]
13: ; preds = %11
%14 = load i8*, i8** %3
%15 = bitcast i8* %14 to i64*
%16 = load i64, i64* %15
store i64 %16, i64* %5
br label %29
17: ; preds = %11
%18 = load i8*, i8** %3
%19 = bitcast i8* %18 to i64*
%20 = load i64, i64* %19
store i64 %20, i64* %5
br label %29
21: ; preds = %11
%22 = load i8*, i8** %3
%23 = bitcast i8* %22 to i64*
%24 = load i64, i64* %23
store i64 %24, i64* %5
br label %29
25: ; preds = %11
%26 = load i8*, i8** %3
%27 = bitcast i8* %26 to i64*
%28 = load i64, i64* %27
store i64 %28, i64* %5
br label %29
29: ; preds = %11, %25, %21, %17, %13
%30 = load i64, i64* %5
%31 = load i32, i32* %4
%32 = call i32 @create_reverse_instruction(i64 %30, i32 %31)
br label %33
33: ; preds = %29, %10
ret void
}

LLVM IR (-O2):
@str = [32 x i8] c"\0A=== Reverse code generator ===\00"
define void @reverse_code_generator(i8* %0, i32 %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
%4 = tail call i64 @is_address_referenced(i8* %0)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %13
6: ; preds = %2
switch i32 %1, label %10 [
i32 1, label %7
i32 2, label %7
i32 4, label %7
i32 8, label %7
]
7: ; preds = %6, %6, %6, %6
%8 = bitcast i8* %0 to i64*
%9 = load i64, i64* %8
br label %10
10: ; preds = %7, %6
%11 = phi i64 [ 0, %6 ], [ %9, %7 ]
%12 = tail call i32 @create_reverse_instruction(i64 %11, i32 %1)
br label %13
13: ; preds = %2, %10
ret void
}