#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__ Elf32_Shdr;

/* Variables and functions */
scalar_t__ has32_rel_mcount(TYPE_1__ const *, TYPE_1__ const *const,
                            char const *const, char const *const);
scalar_t__ w(int /*<<< orphan*/);
unsigned tot32_relsize(Elf32_Shdr const *const shdr0, unsigned nhdr,
                       const char *const shstrtab, const char *const fname) {
  unsigned totrelsz = 0;
  Elf32_Shdr const *shdrp = shdr0;
  for (; nhdr; --nhdr, ++shdrp) {
    if (has32_rel_mcount(shdrp, shdr0, shstrtab, fname))
      totrelsz += w(shdrp->sh_size);
  }
  return totrelsz;
}


x86 assembly (clang, -O0):
<tot32_relsize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%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     11a5 <tot32_relsize+0x85>
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1030 <has32_rel_mcount@plt>
cmp    $0x0,%rax
je     1186 <tot32_relsize+0x66>
mov    -0x30(%rbp),%rax
mov    (%rax),%edi
call   1040 <w@plt>
mov    %rax,%rcx
mov    -0x24(%rbp),%eax
add    %rcx,%rax
mov    %eax,-0x24(%rbp)
jmp    118b <tot32_relsize+0x6b>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
mov    -0x30(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x30(%rbp)
jmp    1146 <tot32_relsize+0x26>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tot32_relsize>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
je     117c <tot32_relsize+0x5c>
mov    %rcx,%r14
mov    %rdx,%r15
mov    %esi,%ebx
mov    %rdi,%r12
xor    %r13d,%r13d
mov    %rdi,%rbp
jmp    1159 <tot32_relsize+0x39>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x4,%rbp
add    $0xffffffff,%ebx
je     117f <tot32_relsize+0x5f>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %r14,%rcx
call   1030 <has32_rel_mcount@plt>
test   %rax,%rax
je     1150 <tot32_relsize+0x30>
mov    0x0(%rbp),%edi
call   1040 <w@plt>
add    %eax,%r13d
jmp    1150 <tot32_relsize+0x30>
xor    %r13d,%r13d
mov    %r13d,%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 @tot32_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__*
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
%11 = load %struct.TYPE_5__*, %struct.TYPE_5__** %5
store %struct.TYPE_5__* %11, %struct.TYPE_5__** %10
br label %12
12: ; preds = %32, %4
%13 = load i32, i32* %6
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %37
15: ; preds = %12
%16 = load %struct.TYPE_5__*, %struct.TYPE_5__** %10
%17 = load %struct.TYPE_5__*, %struct.TYPE_5__** %5
%18 = load i8*, i8** %7
%19 = load i8*, i8** %8
%20 = call i64 @has32_rel_mcount(%struct.TYPE_5__* %16, %struct.TYPE_5__* %17, i8* %18, i8* %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %31
22: ; preds = %15
%23 = load %struct.TYPE_5__*, %struct.TYPE_5__** %10
%24 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %23, i32 0, i32 0
%25 = load i32, i32* %24
%26 = call i64 @w(i32 %25)
%27 = load i32, i32* %9
%28 = zext i32 %27 to i64
%29 = add nsw i64 %28, %26
%30 = trunc i64 %29 to i32
store i32 %30, i32* %9
br label %31
31: ; preds = %22, %15
br label %32
32: ; preds = %31
%33 = load i32, i32* %6
%34 = add i32 %33, -1
store i32 %34, i32* %6
%35 = load %struct.TYPE_5__*, %struct.TYPE_5__** %10
%36 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %35, i32 1
store %struct.TYPE_5__* %36, %struct.TYPE_5__** %10
br label %12
37: ; preds = %12
%38 = load i32, i32* %9
ret i32 %38
}

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