#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 st_name;
  int /*<<< orphan*/ st_shndx;
};
typedef TYPE_1__ Elf32_Sym;

/* Variables and functions */
char *sec_name(int /*<<< orphan*/);
const char *sym_name(const char *sym_strtab, Elf32_Sym *sym) {
  const char *name;
  name = "<noname>";
  if (sym->st_name) {
    name = sym_strtab + sym->st_name;
  } else {
    name = sec_name(sym->st_shndx);
  }
  return name;
}


x86 assembly (clang, -O0):
<sym_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xed9(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
je     114f <sym_name+0x3f>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq (%rcx),%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    115f <sym_name+0x4f>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
call   1030 <sec_name@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sym_name>:
movslq (%rsi),%rax
test   %rax,%rax
je     111f <sym_name+0xf>
add    %rax,%rdi
mov    %rdi,%rax
ret
mov    0x4(%rsi),%edi
jmp    1030 <sec_name@plt>

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32, i32 }
@.str = [9 x i8] c"<noname>\00"
define i8* @sym_name(i8* %0, %struct.TYPE_3__* %1) {
%3 = alloca i8*
%4 = alloca %struct.TYPE_3__*
%5 = alloca i8*
store i8* %0, i8** %3
store %struct.TYPE_3__* %1, %struct.TYPE_3__** %4
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %5
%6 = load %struct.TYPE_3__*, %struct.TYPE_3__** %4
%7 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %6, i32 0, i32 0
%8 = load i32, i32* %7
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %17
10: ; preds = %2
%11 = load i8*, i8** %3
%12 = load %struct.TYPE_3__*, %struct.TYPE_3__** %4
%13 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %12, i32 0, i32 0
%14 = load i32, i32* %13
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %11, i64 %15
store i8* %16, i8** %5
br label %22
17: ; preds = %2
%18 = load %struct.TYPE_3__*, %struct.TYPE_3__** %4
%19 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %18, i32 0, i32 1
%20 = load i32, i32* %19
%21 = call i8* @sec_name(i32 %20)
store i8* %21, i8** %5
br label %22
22: ; preds = %17, %10
%23 = load i8*, i8** %5
ret i8* %23
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32, i32 }
define i8* @sym_name(i8* readnone %0, %struct.TYPE_3__* nocapture %1) {
%3 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %1, i64 0, i32 0
%4 = load i32, i32* %3
%5 = icmp eq i32 %4, 0
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = sext i32 %4 to i64
%8 = getelementptr inbounds i8, i8* %0, i64 %7
br label %13
9: ; preds = %2
%10 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %1, i64 0, i32 1
%11 = load i32, i32* %10
%12 = tail call i8* @sec_name(i32 %11)
br label %13
13: ; preds = %9, %6
%14 = phi i8* [ %8, %6 ], [ %12, %9 ]
ret i8* %14
}