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

/* Type definitions */
struct TYPE_5__ {
  int /*<<< orphan*/ sh_size;
};
typedef TYPE_1__ Elf64_Shdr;

/* Variables and functions */
char *has64_rel_mcount(TYPE_1__ const *, TYPE_1__ const *const,
                       char const *const, char const *const);
scalar_t__ is_mcounted_section_name(char const *);
scalar_t__ w8(int /*<<< orphan*/);
unsigned tot64_relsize(Elf64_Shdr const *const shdr0, unsigned nhdr,
                       const char *const shstrtab, const char *const fname) {
  unsigned totrelsz = 0;
  Elf64_Shdr const *shdrp = shdr0;
  char const *txtname;
  for (; nhdr; --nhdr, ++shdrp) {
    txtname = has64_rel_mcount(shdrp, shdr0, shstrtab, fname);
    if (txtname && is_mcounted_section_name(txtname)) {
      totrelsz += w8(shdrp->sh_size);
    }
  }
  return totrelsz;
}


x86 assembly (clang, -O0):
<tot64_relsize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11cd <tot64_relsize+0x9d>
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1040 <has64_rel_mcount@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     11ae <tot64_relsize+0x7e>
mov    -0x38(%rbp),%rdi
call   1030 <is_mcounted_section_name@plt>
cmp    $0x0,%rax
je     11ae <tot64_relsize+0x7e>
mov    -0x30(%rbp),%rax
mov    (%rax),%edi
call   1050 <w8@plt>
mov    %rax,%rcx
mov    -0x24(%rbp),%eax
add    %rcx,%rax
mov    %eax,-0x24(%rbp)
jmp    11b3 <tot64_relsize+0x83>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
mov    -0x30(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x30(%rbp)
jmp    1156 <tot64_relsize+0x26>
mov    -0x24(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tot64_relsize>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
je     1198 <tot64_relsize+0x68>
mov    %rcx,%r14
mov    %rdx,%r12
mov    %esi,%ebp
mov    %rdi,%r13
xor    %r15d,%r15d
mov    %rdi,%rbx
jmp    1169 <tot64_relsize+0x39>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x4,%rbx
add    $0xffffffff,%ebp
je     119b <tot64_relsize+0x6b>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
mov    %r14,%rcx
call   1040 <has64_rel_mcount@plt>
test   %rax,%rax
je     1160 <tot64_relsize+0x30>
mov    %rax,%rdi
call   1030 <is_mcounted_section_name@plt>
test   %rax,%rax
je     1160 <tot64_relsize+0x30>
mov    (%rbx),%edi
call   1050 <w8@plt>
add    %eax,%r15d
jmp    1160 <tot64_relsize+0x30>
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_5__ = type { i32 }
define i32 @tot64_relsize(%struct.TYPE_5__* %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca %struct.TYPE_5__*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca %struct.TYPE_5__*
%11 = alloca i8*
store %struct.TYPE_5__* %0, %struct.TYPE_5__** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i8* %3, i8** %8
store i32 0, i32* %9
%12 = load %struct.TYPE_5__*, %struct.TYPE_5__** %5
store %struct.TYPE_5__* %12, %struct.TYPE_5__** %10
br label %13
13: ; preds = %38, %4
%14 = load i32, i32* %6
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %43
16: ; preds = %13
%17 = load %struct.TYPE_5__*, %struct.TYPE_5__** %10
%18 = load %struct.TYPE_5__*, %struct.TYPE_5__** %5
%19 = load i8*, i8** %7
%20 = load i8*, i8** %8
%21 = call i8* @has64_rel_mcount(%struct.TYPE_5__* %17, %struct.TYPE_5__* %18, i8* %19, i8* %20)
store i8* %21, i8** %11
%22 = load i8*, i8** %11
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %37
24: ; preds = %16
%25 = load i8*, i8** %11
%26 = call i64 @is_mcounted_section_name(i8* %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %37
28: ; preds = %24
%29 = load %struct.TYPE_5__*, %struct.TYPE_5__** %10
%30 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %29, i32 0, i32 0
%31 = load i32, i32* %30
%32 = call i64 @w8(i32 %31)
%33 = load i32, i32* %9
%34 = zext i32 %33 to i64
%35 = add nsw i64 %34, %32
%36 = trunc i64 %35 to i32
store i32 %36, i32* %9
br label %37
37: ; preds = %28, %24, %16
br label %38
38: ; preds = %37
%39 = load i32, i32* %6
%40 = add i32 %39, -1
store i32 %40, i32* %6
%41 = load %struct.TYPE_5__*, %struct.TYPE_5__** %10
%42 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %41, i32 1
store %struct.TYPE_5__* %42, %struct.TYPE_5__** %10
br label %13
43: ; preds = %13
%44 = load i32, i32* %9
ret i32 %44
}

LLVM IR (-O2):
%struct.TYPE_5__ = type { i32 }
define i32 @tot64_relsize(%struct.TYPE_5__* %0, i32 %1, i8* %2, i8* %3) {
%5 = icmp eq i32 %1, 0
br i1 %5, label %26, label %6
6: ; preds = %4, %21
%7 = phi i32 [ %23, %21 ], [ %1, %4 ]
%8 = phi %struct.TYPE_5__* [ %24, %21 ], [ %0, %4 ]
%9 = phi i32 [ %22, %21 ], [ 0, %4 ]
%10 = tail call i8* @has64_rel_mcount(%struct.TYPE_5__* %8, %struct.TYPE_5__* %0, i8* %2, i8* %3)
%11 = icmp eq i8* %10, null
br i1 %11, label %21, label %12
12: ; preds = %6
%13 = tail call i64 @is_mcounted_section_name(i8* %10)
%14 = icmp eq i64 %13, 0
br i1 %14, label %21, label %15
15: ; preds = %12
%16 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %8, i64 0, i32 0
%17 = load i32, i32* %16
%18 = tail call i64 @w8(i32 %17)
%19 = trunc i64 %18 to i32
%20 = add i32 %9, %19
br label %21
21: ; preds = %6, %12, %15
%22 = phi i32 [ %20, %15 ], [ %9, %12 ], [ %9, %6 ]
%23 = add i32 %7, -1
%24 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %8, i64 1
%25 = icmp eq i32 %23, 0
br i1 %25, label %26, label %6
26: ; preds = %21, %4
%27 = phi i32 [ 0, %4 ], [ %22, %21 ]
ret i32 %27
}