#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_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  int sh_offset;
};
typedef TYPE_1__ Elf64_Shdr;
typedef size_t Elf64_Half;

/* Variables and functions */
size_t SHN_UNDEF;
char *fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
char *get_shstrtab(Elf64_Shdr *shtab, Elf64_Half strndx, char *addr) {
  if (strndx == SHN_UNDEF)
    return (fprintf(stderr, "cannot get section header string table index"),
            NULL);
  return (addr + shtab[strndx].sh_offset);
}


x86 assembly (clang, -O0):
<get_shstrtab>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2ea9(%rip),%rcx
cmp    (%rcx),%rax
jne    115a <get_shstrtab+0x4a>
mov    0x2ea1(%rip),%rax
mov    (%rax),%edi
lea    0xeb8(%rip),%rsi
call   1030 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1171 <get_shstrtab+0x61>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%rdx
movslq (%rcx,%rdx,4),%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_shstrtab>:
push   %rax
mov    0x2ec0(%rip),%rcx
cmp    %rsi,(%rcx)
jne    1136 <get_shstrtab+0x26>
mov    0x2ebc(%rip),%rax
mov    (%rax),%edi
lea    0xed3(%rip),%rsi
call   1030 <fprintf@plt>
xor    %eax,%eax
pop    %rcx
ret
mov    %rdx,%rax
movslq (%rdi,%rsi,4),%rcx
add    %rcx,%rax
pop    %rcx
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32 }
@SHN_UNDEF = global i64 0
@stderr = global i32 0
@.str = [45 x i8] c"cannot get section header string table index\00"
define i8* @get_shstrtab(%struct.TYPE_3__* %0, i64 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca %struct.TYPE_3__*
%6 = alloca i64
%7 = alloca i8*
store %struct.TYPE_3__* %0, %struct.TYPE_3__** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
%8 = load i64, i64* %6
%9 = load i64, i64* @SHN_UNDEF
%10 = icmp eq i64 %8, %9
br i1 %10, label %11, label %14
11: ; preds = %3
%12 = load i32, i32* @stderr
%13 = call i8* @fprintf(i32 %12, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %4
br label %23
14: ; preds = %3
%15 = load i8*, i8** %7
%16 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%17 = load i64, i64* %6
%18 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %16, i64 %17
%19 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %18, i32 0, i32 0
%20 = load i32, i32* %19
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %15, i64 %21
store i8* %22, i8** %4
br label %23
23: ; preds = %14, %11
%24 = load i8*, i8** %4
ret i8* %24
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32 }
@SHN_UNDEF = global i64 0
@stderr = global i32 0
@.str = [45 x i8] c"cannot get section header string table index\00"
define i8* @get_shstrtab(%struct.TYPE_3__* nocapture %0, i64 %1, i8* readnone %2) {
%4 = load i64, i64* @SHN_UNDEF
%5 = icmp eq i64 %4, %1
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = load i32, i32* @stderr
%8 = tail call i8* @fprintf(i32 %7, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
br label %14
9: ; preds = %3
%10 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %0, i64 %1, i32 0
%11 = load i32, i32* %10
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %2, i64 %12
br label %14
14: ; preds = %9, %6
%15 = phi i8* [ null, %6 ], [ %13, %9 ]
ret i8* %15
}