#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_1__;

/* Type definitions */
struct TYPE_4__ {
  int /*<<< orphan*/ sh_type;
  int /*<<< orphan*/ sh_name;
  int /*<<< orphan*/ sh_info;
};
typedef TYPE_1__ Elf64_Shdr;

/* Variables and functions */
size_t SHT_PROGBITS;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *const);
int /*<<< orphan*/ is_mcounted_section_name(char const *const);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char const *const);
int /*<<< orphan*/ succeed_file();
size_t w(int /*<<< orphan*/);
char const *__has64_rel_mcount(Elf64_Shdr const *const relhdr,
                               Elf64_Shdr const *const shdr0,
                               char const *const shstrtab,
                               char const *const fname) {
  Elf64_Shdr const *const txthdr = &shdr0[w(relhdr->sh_info)];
  char const *const txtname = &shstrtab[w(txthdr->sh_name)];
  if (0 == strcmp("__mcount_loc", txtname)) {
    fprintf(stderr, "warning: __mcount_loc already exists: %s\n", fname);
    succeed_file();
  }
  if (SHT_PROGBITS != w(txthdr->sh_type) || !is_mcounted_section_name(txtname))
    return NULL;
  return txtname;
}


x86 assembly (clang, -O0):
<__has64_rel_mcount>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%edi
call   1070 <w@plt>
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rax
mov    0x4(%rax),%edi
call   1070 <w@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rsi
lea    0xe45(%rip),%rdi
call   1050 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    11ee <__has64_rel_mcount+0x9e>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xe2b(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x0,%al
call   1030 <succeed_file@plt>
mov    0x2de3(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x50(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%edi
call   1070 <w@plt>
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
cmp    %rcx,%rax
jne    1229 <__has64_rel_mcount+0xd9>
mov    -0x38(%rbp),%rdi
call   1040 <is_mcounted_section_name@plt>
cmp    $0x0,%eax
jne    1236 <__has64_rel_mcount+0xe6>
movq   $0x0,-0x8(%rbp)
jmp    123e <__has64_rel_mcount+0xee>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__has64_rel_mcount>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%r14
mov    0x8(%rdi),%edi
call   1070 <w@plt>
lea    (%rax,%rax,2),%r13
mov    0x4(%r14,%r13,4),%edi
call   1070 <w@plt>
mov    %rax,%rbx
add    %r12,%rbx
lea    0xe7b(%rip),%rdi
mov    %rbx,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    11b1 <__has64_rel_mcount+0x61>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
lea    0xe6b(%rip),%rsi
mov    %r15,%rdx
call   1060 <fprintf@plt>
xor    %eax,%eax
call   1030 <succeed_file@plt>
mov    0x2e20(%rip),%rax
mov    (%rax),%r15
mov    (%r14,%r13,4),%edi
call   1070 <w@plt>
cmp    %rax,%r15
jne    11dd <__has64_rel_mcount+0x8d>
mov    %rbx,%rdi
call   1040 <is_mcounted_section_name@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
cmovne %rbx,%rax
jmp    11df <__has64_rel_mcount+0x8f>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.TYPE_4__ = type { i32, i32, i32 }
@.str = [13 x i8] c"__mcount_loc\00"
@stderr = global i32 0
@.str.1 = [42 x i8] c"warning: __mcount_loc already exists: %s\0A\00"
@SHT_PROGBITS = global i64 0
define i8* @__has64_rel_mcount(%struct.TYPE_4__* %0, %struct.TYPE_4__* %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca %struct.TYPE_4__*
%7 = alloca %struct.TYPE_4__*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca %struct.TYPE_4__*
%11 = alloca i8*
store %struct.TYPE_4__* %0, %struct.TYPE_4__** %6
store %struct.TYPE_4__* %1, %struct.TYPE_4__** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
%12 = load %struct.TYPE_4__*, %struct.TYPE_4__** %7
%13 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%14 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %13, i32 0, i32 2
%15 = load i32, i32* %14
%16 = call i64 @w(i32 %15)
%17 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %12, i64 %16
store %struct.TYPE_4__* %17, %struct.TYPE_4__** %10
%18 = load i8*, i8** %8
%19 = load %struct.TYPE_4__*, %struct.TYPE_4__** %10
%20 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %19, i32 0, i32 1
%21 = load i32, i32* %20
%22 = call i64 @w(i32 %21)
%23 = getelementptr inbounds i8, i8* %18, i64 %22
store i8* %23, i8** %11
%24 = load i8*, i8** %11
%25 = call i64 @strcmp(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %24)
%26 = icmp eq i64 0, %25
br i1 %26, label %27, label %32
27: ; preds = %4
%28 = load i32, i32* @stderr
%29 = load i8*, i8** %9
%30 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* %29)
%31 = call i32 (...) @succeed_file()
br label %32
32: ; preds = %27, %4
%33 = load i64, i64* @SHT_PROGBITS
%34 = load %struct.TYPE_4__*, %struct.TYPE_4__** %10
%35 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %34, i32 0, i32 0
%36 = load i32, i32* %35
%37 = call i64 @w(i32 %36)
%38 = icmp ne i64 %33, %37
br i1 %38, label %43, label %39
39: ; preds = %32
%40 = load i8*, i8** %11
%41 = call i32 @is_mcounted_section_name(i8* %40)
%42 = icmp ne i32 %41, 0
br i1 %42, label %44, label %43
43: ; preds = %39, %32
store i8* null, i8** %5
br label %46
44: ; preds = %39
%45 = load i8*, i8** %11
store i8* %45, i8** %5
br label %46
46: ; preds = %44, %43
%47 = load i8*, i8** %5
ret i8* %47
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i32, i32, i32 }
@.str = [13 x i8] c"__mcount_loc\00"
@stderr = global i32 0
@.str.1 = [42 x i8] c"warning: __mcount_loc already exists: %s\0A\00"
@SHT_PROGBITS = global i64 0
define i8* @__has64_rel_mcount(%struct.TYPE_4__* nocapture %0, %struct.TYPE_4__* nocapture %1, i8* %2, i8* %3) {
%5 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %0, i64 0, i32 2
%6 = load i32, i32* %5
%7 = tail call i64 @w(i32 %6)
%8 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %1, i64 %7, i32 1
%9 = load i32, i32* %8
%10 = tail call i64 @w(i32 %9)
%11 = getelementptr inbounds i8, i8* %2, i64 %10
%12 = tail call i64 @strcmp(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %4
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%17 = tail call i32 (...) @succeed_file()
br label %18
18: ; preds = %14, %4
%19 = load i64, i64* @SHT_PROGBITS
%20 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %1, i64 %7, i32 0
%21 = load i32, i32* %20
%22 = tail call i64 @w(i32 %21)
%23 = icmp eq i64 %19, %22
br i1 %23, label %24, label %28
24: ; preds = %18
%25 = tail call i32 @is_mcounted_section_name(i8* %11)
%26 = icmp eq i32 %25, 0
%27 = select i1 %26, i8* null, i8* %11
br label %28
28: ; preds = %24, %18
%29 = phi i8* [ null, %18 ], [ %27, %24 ]
ret i8* %29
}