#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_9__ TYPE_2__;
typedef struct TYPE_8__ TYPE_1__;

/* Type definitions */
struct TYPE_9__ {
  int e_shnum;
};
struct TYPE_8__ {
  size_t sh_name;
};
typedef TYPE_1__ Elf32_Shdr;
typedef TYPE_2__ Elf32_Ehdr;

/* Variables and functions */
int /*<<< orphan*/ do_rel(int *, int *, int, TYPE_1__ *, int);
int get_sym_number(int, TYPE_2__ *, TYPE_1__ *, char const *);
int /*<<< orphan*/ strcmp(char const *, char *);
void find_rel(int *plt, int *offset, int fd, const char *string,
              Elf32_Ehdr *ehdr, Elf32_Shdr *shdr, const char *sh_function) {
  Elf32_Shdr *shdrp = shdr;
  int sym;
  int i;
  sym = get_sym_number(fd, ehdr, shdr, sh_function);
  if (sym < 0) {
    *plt = -1;
    *offset = -1;
    return;
  }
  for (i = 0; i < ehdr->e_shnum; i++) {
    if (!strcmp(&string[shdrp->sh_name], ".rel.plt")) {
      do_rel(plt, offset, fd, shdrp, sym);
      return;
    }
    ++shdrp;
  }
}


x86 assembly (clang, -O0):
<find_rel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    0x10(%rbp),%rcx
call   1050 <get_sym_number@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jge    1195 <find_rel+0x65>
mov    -0x8(%rbp),%rax
movl   $0xffffffff,(%rax)
mov    -0x10(%rbp),%rax
movl   $0xffffffff,(%rax)
jmp    1202 <find_rel+0xd2>
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
mov    -0x28(%rbp),%rcx
cmp    (%rcx),%eax
jge    1202 <find_rel+0xd2>
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rax
add    (%rax),%rdi
lea    0xe43(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    11e8 <find_rel+0xb8>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x38(%rbp),%rcx
mov    -0x3c(%rbp),%r8d
call   1030 <do_rel@plt>
jmp    1202 <find_rel+0xd2>
mov    -0x38(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x38(%rbp)
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    119c <find_rel+0x6c>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_rel>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,%rbx
mov    %r8,%r14
mov    %rcx,%rbp
mov    %rsi,%r12
mov    %rdi,%r15
mov    0x50(%rsp),%rcx
mov    %edx,0x4(%rsp)
mov    %edx,%edi
mov    %r8,%rsi
mov    %r9,%rdx
call   1050 <get_sym_number@plt>
test   %eax,%eax
js     11ae <find_rel+0x7e>
mov    %r15,0x8(%rsp)
mov    %r12,0x10(%rsp)
mov    (%r14),%r12d
test   %r12d,%r12d
jle    11bd <find_rel+0x8d>
mov    %eax,%r13d
lea    0xe7d(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%rbx),%rdi
add    %rbp,%rdi
mov    %r14,%rsi
call   1040 <strcmp@plt>
test   %eax,%eax
je     11cc <find_rel+0x9c>
add    $0x8,%rbx
add    $0xffffffff,%r12d
jne    1190 <find_rel+0x60>
jmp    11bd <find_rel+0x8d>
movl   $0xffffffff,(%r15)
movl   $0xffffffff,(%r12)
ff
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%rsp),%rdi
mov    0x10(%rsp),%rsi
mov    0x4(%rsp),%edx
mov    %rbx,%rcx
mov    %r13d,%r8d
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <do_rel@plt>

LLVM IR (-O0):
%struct.TYPE_9__ = type { i32 }
%struct.TYPE_8__ = type { i64 }
@.str = [9 x i8] c".rel.plt\00"
define void @find_rel(i32* %0, i32* %1, i32 %2, i8* %3, %struct.TYPE_9__* %4, %struct.TYPE_8__* %5, i8* %6) {
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i8*
%12 = alloca %struct.TYPE_9__*
%13 = alloca %struct.TYPE_8__*
%14 = alloca i8*
%15 = alloca %struct.TYPE_8__*
%16 = alloca i32
%17 = alloca i32
store i32* %0, i32** %8
store i32* %1, i32** %9
store i32 %2, i32* %10
store i8* %3, i8** %11
store %struct.TYPE_9__* %4, %struct.TYPE_9__** %12
store %struct.TYPE_8__* %5, %struct.TYPE_8__** %13
store i8* %6, i8** %14
%18 = load %struct.TYPE_8__*, %struct.TYPE_8__** %13
store %struct.TYPE_8__* %18, %struct.TYPE_8__** %15
%19 = load i32, i32* %10
%20 = load %struct.TYPE_9__*, %struct.TYPE_9__** %12
%21 = load %struct.TYPE_8__*, %struct.TYPE_8__** %13
%22 = load i8*, i8** %14
%23 = call i32 @get_sym_number(i32 %19, %struct.TYPE_9__* %20, %struct.TYPE_8__* %21, i8* %22)
store i32 %23, i32* %16
%24 = load i32, i32* %16
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %7
%27 = load i32*, i32** %8
store i32 -1, i32* %27
%28 = load i32*, i32** %9
store i32 -1, i32* %28
br label %57
29: ; preds = %7
store i32 0, i32* %17
br label %30
30: ; preds = %54, %29
%31 = load i32, i32* %17
%32 = load %struct.TYPE_9__*, %struct.TYPE_9__** %12
%33 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %32, i32 0, i32 0
%34 = load i32, i32* %33
%35 = icmp slt i32 %31, %34
br i1 %35, label %36, label %57
36: ; preds = %30
%37 = load i8*, i8** %11
%38 = load %struct.TYPE_8__*, %struct.TYPE_8__** %15
%39 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %38, i32 0, i32 0
%40 = load i64, i64* %39
%41 = getelementptr inbounds i8, i8* %37, i64 %40
%42 = call i32 @strcmp(i8* %41, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%43 = icmp ne i32 %42, 0
br i1 %43, label %51, label %44
44: ; preds = %36
%45 = load i32*, i32** %8
%46 = load i32*, i32** %9
%47 = load i32, i32* %10
%48 = load %struct.TYPE_8__*, %struct.TYPE_8__** %15
%49 = load i32, i32* %16
%50 = call i32 @do_rel(i32* %45, i32* %46, i32 %47, %struct.TYPE_8__* %48, i32 %49)
br label %57
51: ; preds = %36
%52 = load %struct.TYPE_8__*, %struct.TYPE_8__** %15
%53 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %52, i32 1
store %struct.TYPE_8__* %53, %struct.TYPE_8__** %15
br label %54
54: ; preds = %51
%55 = load i32, i32* %17
%56 = add nsw i32 %55, 1
store i32 %56, i32* %17
br label %30
57: ; preds = %26, %44, %30
ret void
}

LLVM IR (-O2):
%struct.TYPE_9__ = type { i32 }
%struct.TYPE_8__ = type { i64 }
@.str = [9 x i8] c".rel.plt\00"
define void @find_rel(i32* %0, i32* %1, i32 %2, i8* nocapture %3, %struct.TYPE_9__* %4, %struct.TYPE_8__* %5, i8* %6) {
%8 = tail call i32 @get_sym_number(i32 %2, %struct.TYPE_9__* %4, %struct.TYPE_8__* %5, i8* %6)
%9 = icmp slt i32 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %7
%11 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %4, i64 0, i32 0
%12 = load i32, i32* %11
%13 = icmp sgt i32 %12, 0
br i1 %13, label %15, label %29
14: ; preds = %7
store i32 -1, i32* %0
store i32 -1, i32* %1
br label %29
15: ; preds = %10, %25
%16 = phi i32 [ %27, %25 ], [ 0, %10 ]
%17 = phi %struct.TYPE_8__* [ %26, %25 ], [ %5, %10 ]
%18 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %17, i64 0, i32 0
%19 = load i64, i64* %18
%20 = getelementptr inbounds i8, i8* %3, i64 %19
%21 = tail call i32 @strcmp(i8* dereferenceable(1) %20, i8* dereferenceable(9) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %15
%24 = tail call i32 @do_rel(i32* %0, i32* %1, i32 %2, %struct.TYPE_8__* %17, i32 %8)
br label %29
25: ; preds = %15
%26 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %17, i64 1
%27 = add nuw nsw i32 %16, 1
%28 = icmp eq i32 %27, %12
br i1 %28, label %29, label %15
29: ; preds = %25, %10, %23, %14
ret void
}