#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 */
#define R_ARM_ABS32 132
#define R_ARM_COPY 131
#define R_ARM_GLOB_DAT 130
#define R_ARM_JUMP_SLOT 129
#define R_ARM_RELATIVE 128
int /*<<< orphan*/ memcpy(size_t *, void *, size_t);
void do_single_reloc(size_t *reloc_addr, int type, size_t sym_val,
                     size_t sym_size, unsigned char *base_addr, size_t addend) {
  switch (type) {
  case R_ARM_ABS32:
    *reloc_addr += sym_val;
    break;
  case R_ARM_GLOB_DAT:
  case R_ARM_JUMP_SLOT:
    *reloc_addr = sym_val;
    break;
  case R_ARM_RELATIVE:
    *reloc_addr += (size_t)base_addr;
    break;
  case R_ARM_COPY:
    memcpy(reloc_addr, (void *)sym_val, sym_size);
    break;
  }
}


x86 assembly (clang, -O0):
<do_single_reloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x38(%rbp)
sub    $0x4,%eax
ja     119f <do_single_reloc+0x8f>
mov    -0x38(%rbp),%rax
lea    0xeb1(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rax
add    (%rax),%rcx
mov    %rcx,(%rax)
jmp    119f <do_single_reloc+0x8f>
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
jmp    119f <do_single_reloc+0x8f>
mov    -0x28(%rbp),%rcx
mov    -0x8(%rbp),%rax
add    (%rax),%rcx
mov    %rcx,(%rax)
jmp    119f <do_single_reloc+0x8f>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <memcpy@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_single_reloc>:
add    $0xffffff80,%esi
cmp    $0x4,%esi
ja     113e <do_single_reloc+0x2e>
lea    0xee1(%rip),%rax
movslq (%rax,%rsi,4),%rsi
add    %rax,%rsi
jmp    *%rsi
mov    %rdx,(%rdi)
ret
add    %r8,(%rdi)
ret
mov    %rdx,%rsi
mov    %rcx,%rdx
jmp    1030 <memcpy@plt>
add    %rdx,(%rdi)
ret

LLVM IR (-O0):
define void @do_single_reloc(i64* %0, i32 %1, i64 %2, i64 %3, i8* %4, i64 %5) {
%7 = alloca i64*
%8 = alloca i32
%9 = alloca i64
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i64
store i64* %0, i64** %7
store i32 %1, i32* %8
store i64 %2, i64* %9
store i64 %3, i64* %10
store i8* %4, i8** %11
store i64 %5, i64* %12
%13 = load i32, i32* %8
switch i32 %13, label %34 [
i32 132, label %14
i32 130, label %19
i32 129, label %19
i32 128, label %22
i32 131, label %28
]
14: ; preds = %6
%15 = load i64, i64* %9
%16 = load i64*, i64** %7
%17 = load i64, i64* %16
%18 = add i64 %17, %15
store i64 %18, i64* %16
br label %34
19: ; preds = %6, %6
%20 = load i64, i64* %9
%21 = load i64*, i64** %7
store i64 %20, i64* %21
br label %34
22: ; preds = %6
%23 = load i8*, i8** %11
%24 = ptrtoint i8* %23 to i64
%25 = load i64*, i64** %7
%26 = load i64, i64* %25
%27 = add i64 %26, %24
store i64 %27, i64* %25
br label %34
28: ; preds = %6
%29 = load i64*, i64** %7
%30 = load i64, i64* %9
%31 = inttoptr i64 %30 to i8*
%32 = load i64, i64* %10
%33 = call i32 @memcpy(i64* %29, i8* %31, i64 %32)
br label %34
34: ; preds = %6, %28, %22, %19, %14
ret void
}

LLVM IR (-O2):
define void @do_single_reloc(i64* %0, i32 %1, i64 %2, i64 %3, i8* %4, i64 %5) {
switch i32 %1, label %18 [
i32 132, label %7
i32 130, label %10
i32 129, label %10
i32 128, label %11
i32 131, label %15
]
7: ; preds = %6
%8 = load i64, i64* %0
%9 = add i64 %8, %2
store i64 %9, i64* %0
br label %18
10: ; preds = %6, %6
store i64 %2, i64* %0
br label %18
11: ; preds = %6
%12 = ptrtoint i8* %4 to i64
%13 = load i64, i64* %0
%14 = add i64 %13, %12
store i64 %14, i64* %0
br label %18
15: ; preds = %6
%16 = inttoptr i64 %2 to i8*
%17 = tail call i32 @memcpy(i64* %0, i8* %16, i64 %3)
br label %18
18: ; preds = %6, %15, %11, %10, %7
ret void
}