#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_flags;
  int /*<<< orphan*/ sh_type;
  int /*<<< orphan*/ sh_name;
  int /*<<< orphan*/ sh_info;
};
typedef TYPE_1__ Elf32_Shdr;

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


x86 assembly (clang, -O0):
<__has32_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    0xc(%rax),%edi
call   1060 <w@plt>
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%edi
call   1060 <w@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rsi
lea    0xe55(%rip),%rdi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11da <__has32_rel_mcount+0x9a>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xe3f(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x0,%al
call   1030 <succeed_file@plt>
mov    -0x30(%rbp),%rax
mov    0x4(%rax),%edi
call   1060 <w@plt>
mov    0x2de3(%rip),%rcx
cmp    (%rcx),%rax
jne    1215 <__has32_rel_mcount+0xd5>
mov    -0x30(%rbp),%rax
mov    (%rax),%edi
call   1060 <w@plt>
mov    0x2de0(%rip),%rcx
and    (%rcx),%rax
cmp    $0x0,%rax
jne    1222 <__has32_rel_mcount+0xe2>
movq   $0x0,-0x8(%rbp)
jmp    122a <__has32_rel_mcount+0xea>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__has32_rel_mcount>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rcx,%r12
mov    %rdx,%r13
mov    %rsi,%r14
mov    0xc(%rdi),%edi
call   1060 <w@plt>
mov    %rax,%r15
shl    $0x4,%r15
mov    0x8(%r14,%r15,1),%edi
call   1060 <w@plt>
mov    %rax,%rbx
add    %r13,%rbx
lea    0xe88(%rip),%rdi
mov    %rbx,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    11a4 <__has32_rel_mcount+0x64>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
lea    0xe78(%rip),%rsi
mov    %r12,%rdx
call   1050 <fprintf@plt>
xor    %eax,%eax
call   1030 <succeed_file@plt>
mov    0x4(%r14,%r15,1),%edi
call   1060 <w@plt>
mov    0x2e1b(%rip),%rcx
cmp    (%rcx),%rax
jne    11d3 <__has32_rel_mcount+0x93>
mov    (%r14,%r15,1),%edi
call   1060 <w@plt>
mov    0x2e1e(%rip),%rcx
and    (%rcx),%rax
cmove  %rax,%rbx
jmp    11d5 <__has32_rel_mcount+0x95>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.TYPE_4__ = type { i32, 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
@SHF_EXECINSTR = global i64 0
define i8* @__has32_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 3
%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 2
%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 %25, 0
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 %struct.TYPE_4__*, %struct.TYPE_4__** %10
%34 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %33, i32 0, i32 1
%35 = load i32, i32* %34
%36 = call i64 @w(i32 %35)
%37 = load i64, i64* @SHT_PROGBITS
%38 = icmp ne i64 %36, %37
br i1 %38, label %47, label %39
39: ; preds = %32
%40 = load %struct.TYPE_4__*, %struct.TYPE_4__** %10
%41 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %40, i32 0, i32 0
%42 = load i32, i32* %41
%43 = call i64 @w(i32 %42)
%44 = load i64, i64* @SHF_EXECINSTR
%45 = and i64 %43, %44
%46 = icmp ne i64 %45, 0
br i1 %46, label %48, label %47
47: ; preds = %39, %32
store i8* null, i8** %5
br label %50
48: ; preds = %39
%49 = load i8*, i8** %11
store i8* %49, i8** %5
br label %50
50: ; preds = %48, %47
%51 = load i8*, i8** %5
ret i8* %51
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i32, 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
@SHF_EXECINSTR = global i64 0
define i8* @__has32_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 3
%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 2
%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 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %1, i64 %7, i32 1
%20 = load i32, i32* %19
%21 = tail call i64 @w(i32 %20)
%22 = load i64, i64* @SHT_PROGBITS
%23 = icmp eq i64 %21, %22
br i1 %23, label %24, label %32
24: ; preds = %18
%25 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %1, i64 %7, i32 0
%26 = load i32, i32* %25
%27 = tail call i64 @w(i32 %26)
%28 = load i64, i64* @SHF_EXECINSTR
%29 = and i64 %28, %27
%30 = icmp eq i64 %29, 0
%31 = select i1 %30, i8* null, i8* %11
br label %32
32: ; preds = %24, %18
%33 = phi i8* [ null, %18 ], [ %31, %24 ]
ret i8* %33
}