#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 */
typedef struct TYPE_5__ TYPE_2__;
typedef struct TYPE_4__ TYPE_1__;

/* Type definitions */
typedef scalar_t__ uint16_t;
struct TYPE_5__ {
  scalar_t__ e_shstrndx;
};
struct TYPE_4__ {
  unsigned long long sh_offset;
};
typedef TYPE_1__ Elf64_Shdr;
typedef TYPE_2__ Elf64_Ehdr;

/* Variables and functions */
scalar_t__ SHN_UNDEF;
TYPE_1__ *get_s_header(char *, scalar_t__);
char *get_sh_strtab(char *elf) {
  if (!elf)
    return 0;
  Elf64_Ehdr *ehdr;
  ehdr = (Elf64_Ehdr *)elf;
  uint16_t ind;
  ind = ehdr->e_shstrndx;
  if (ind == SHN_UNDEF)
    return 0;
  unsigned long long addr;
  Elf64_Shdr *shdr;
  shdr = get_s_header(elf, ind);
  if (!shdr)
    return 0;
  addr = (unsigned long long)elf + shdr->sh_offset;
  char *strtab;
  strtab = (char *)addr;
  return strtab;
}


x86 assembly (clang, -O0):
<get_sh_strtab>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1134 <get_sh_strtab+0x24>
movq   $0x0,-0x8(%rbp)
jmp    11b0 <get_sh_strtab+0xa0>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    0x2e8e(%rip),%rcx
cmp    (%rcx),%rax
jne    1168 <get_sh_strtab+0x58>
movq   $0x0,-0x8(%rbp)
jmp    11b0 <get_sh_strtab+0xa0>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <get_s_header@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1191 <get_sh_strtab+0x81>
movq   $0x0,-0x8(%rbp)
jmp    11b0 <get_sh_strtab+0xa0>
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%rcx
add    (%rcx),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_sh_strtab>:
push   %rbx
test   %rdi,%rdi
je     113a <get_sh_strtab+0x2a>
mov    %rdi,%rbx
mov    (%rdi),%rsi
mov    0x2ebd(%rip),%rax
cmp    (%rax),%rsi
je     113a <get_sh_strtab+0x2a>
mov    %rbx,%rdi
call   1030 <get_s_header@plt>
test   %rax,%rax
je     113a <get_sh_strtab+0x2a>
add    (%rax),%rbx
jmp    113c <get_sh_strtab+0x2c>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
%struct.TYPE_5__ = type { i64 }
%struct.TYPE_4__ = type { i64 }
@SHN_UNDEF = global i64 0
define i8* @get_sh_strtab(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca %struct.TYPE_5__*
%5 = alloca i64
%6 = alloca i64
%7 = alloca %struct.TYPE_4__*
%8 = alloca i8*
store i8* %0, i8** %3
%9 = load i8*, i8** %3
%10 = icmp ne i8* %9, null
br i1 %10, label %12, label %11
11: ; preds = %1
store i8* null, i8** %2
br label %39
12: ; preds = %1
%13 = load i8*, i8** %3
%14 = bitcast i8* %13 to %struct.TYPE_5__*
store %struct.TYPE_5__* %14, %struct.TYPE_5__** %4
%15 = load %struct.TYPE_5__*, %struct.TYPE_5__** %4
%16 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %15, i32 0, i32 0
%17 = load i64, i64* %16
store i64 %17, i64* %5
%18 = load i64, i64* %5
%19 = load i64, i64* @SHN_UNDEF
%20 = icmp eq i64 %18, %19
br i1 %20, label %21, label %22
21: ; preds = %12
store i8* null, i8** %2
br label %39
22: ; preds = %12
%23 = load i8*, i8** %3
%24 = load i64, i64* %5
%25 = call %struct.TYPE_4__* @get_s_header(i8* %23, i64 %24)
store %struct.TYPE_4__* %25, %struct.TYPE_4__** %7
%26 = load %struct.TYPE_4__*, %struct.TYPE_4__** %7
%27 = icmp ne %struct.TYPE_4__* %26, null
br i1 %27, label %29, label %28
28: ; preds = %22
store i8* null, i8** %2
br label %39
29: ; preds = %22
%30 = load i8*, i8** %3
%31 = ptrtoint i8* %30 to i64
%32 = load %struct.TYPE_4__*, %struct.TYPE_4__** %7
%33 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %32, i32 0, i32 0
%34 = load i64, i64* %33
%35 = add i64 %31, %34
store i64 %35, i64* %6
%36 = load i64, i64* %6
%37 = inttoptr i64 %36 to i8*
store i8* %37, i8** %8
%38 = load i8*, i8** %8
store i8* %38, i8** %2
br label %39
39: ; preds = %29, %28, %21, %11
%40 = load i8*, i8** %2
ret i8* %40
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i64 }
@SHN_UNDEF = global i64 0
define i8* @get_sh_strtab(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %17, label %3
3: ; preds = %1
%4 = bitcast i8* %0 to i64*
%5 = load i64, i64* %4
%6 = load i64, i64* @SHN_UNDEF
%7 = icmp eq i64 %5, %6
br i1 %7, label %17, label %8
8: ; preds = %3
%9 = tail call %struct.TYPE_4__* @get_s_header(i8* %0, i64 %5)
%10 = icmp eq %struct.TYPE_4__* %9, null
br i1 %10, label %17, label %11
11: ; preds = %8
%12 = ptrtoint i8* %0 to i64
%13 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %9, i64 0, i32 0
%14 = load i64, i64* %13
%15 = add i64 %14, %12
%16 = inttoptr i64 %15 to i8*
br label %17
17: ; preds = %3, %8, %11, %1
%18 = phi i8* [ null, %1 ], [ null, %3 ], [ %16, %11 ], [ null, %8 ]
ret i8* %18
}