#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_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  int e_shoff;
};
struct TYPE_3__ {
  scalar_t__ sh_type;
  int sh_offset;
};
typedef TYPE_1__ Elf32_Shdr;
typedef TYPE_2__ Elf32_Ehdr;

/* Variables and functions */
scalar_t__ SHT_STRTAB;
scalar_t__ SHT_SYMTAB;
unsigned char *st_str(unsigned char *elf, long index) {
  Elf32_Ehdr *ehdr = (Elf32_Ehdr *)elf;
  Elf32_Shdr *shdr = (Elf32_Shdr *)(elf + ehdr->e_shoff);
  while (shdr->sh_type != SHT_SYMTAB)
    shdr++;
  while (shdr->sh_type != SHT_STRTAB)
    shdr++;
  return elf + shdr->sh_offset + index;
}


x86 assembly (clang, -O0):
<st_str>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movslq (%rcx),%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    0x2ea4(%rip),%rcx
cmp    (%rcx),%rax
je     114e <st_str+0x4e>
mov    -0x20(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x20(%rbp)
jmp    1126 <st_str+0x26>
jmp    1153 <st_str+0x53>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    0x2e97(%rip),%rcx
cmp    (%rcx),%rax
je     117b <st_str+0x7b>
mov    -0x20(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x20(%rbp)
jmp    1153 <st_str+0x53>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movslq 0x8(%rcx),%rcx
add    %rcx,%rax
add    -0x10(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<st_str>:
mov    %rdi,%rax
movslq (%rdi),%rcx
mov    0x2ecb(%rip),%rdx
mov    (%rdx),%rdi
add    %rax,%rcx
add    $0xfffffffffffffff0,%rcx
nopw   0x0(%rax,%rax,1)
mov    %rcx,%rdx
add    $0x10,%rcx
cmp    %rdi,0x10(%rdx)
jne    1120 <st_str+0x20>
mov    0x2ec4(%rip),%rdx
mov    (%rdx),%rdx
cmp    %rdx,%rdi
je     114d <st_str+0x4d>
mov    %rcx,%rdi
nop
lea    0x10(%rdi),%rcx
cmp    %rdx,0x10(%rdi)
mov    %rcx,%rdi
jne    1140 <st_str+0x40>
movslq 0x8(%rcx),%rcx
add    %rcx,%rax
add    %rsi,%rax
ret

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

LLVM IR (-O2):
%struct.TYPE_3__ = type { i64, i32 }
@SHT_SYMTAB = global i64 0
@SHT_STRTAB = global i64 0
define i8* @st_str(i8* %0, i64 %1) {
%3 = bitcast i8* %0 to i32*
%4 = load i32, i32* %3
%5 = sext i32 %4 to i64
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = bitcast i8* %6 to %struct.TYPE_3__*
%8 = load i64, i64* @SHT_SYMTAB
br label %9
9: ; preds = %9, %2
%10 = phi %struct.TYPE_3__* [ %7, %2 ], [ %14, %9 ]
%11 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %10, i64 0, i32 0
%12 = load i64, i64* %11
%13 = icmp eq i64 %12, %8
%14 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %10, i64 1
br i1 %13, label %15, label %9
15: ; preds = %9
%16 = load i64, i64* @SHT_STRTAB
%17 = icmp eq i64 %8, %16
br i1 %17, label %24, label %18
18: ; preds = %15, %18
%19 = phi %struct.TYPE_3__* [ %20, %18 ], [ %10, %15 ]
%20 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %19, i64 1
%21 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %20, i64 0, i32 0
%22 = load i64, i64* %21
%23 = icmp eq i64 %22, %16
br i1 %23, label %24, label %18
24: ; preds = %18, %15
%25 = phi %struct.TYPE_3__* [ %10, %15 ], [ %20, %18 ]
%26 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %25, i64 0, i32 1
%27 = load i32, i32* %26
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %0, i64 %28
%30 = getelementptr inbounds i8, i8* %29, i64 %1
ret i8* %30
}