#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 */

/* Type definitions */
struct ar_hdr {
  int *ar_fmag;
  int /*<<< orphan*/ ar_size;
};
typedef int off_t;
typedef int /*<<< orphan*/ ah;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int SARMAG;
unsigned long atol(int /*<<< orphan*/);
scalar_t__ fread(struct ar_hdr *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ have_object(int, char const *);
int /*<<< orphan*/ load_object(int /*<<< orphan*/ *, int, int, char const *);
int /*<<< orphan*/ xfseek(int /*<<< orphan*/ *, int);
void process_library(const char *name, FILE *fp) {
  static struct ar_hdr ah;
  off_t pos = SARMAG;
  unsigned long size;
  while (1) {
    xfseek(fp, pos);
    if (fread(&ah, sizeof(ah), 1, fp) == 0)
      break;
    if (ah.ar_fmag[0] != 96 || ah.ar_fmag[1] != '\n')
      break;
    size = atol(ah.ar_size);
    pos += sizeof(ah);
    if (!have_object(pos, name))
      load_object(fp, pos, 1, name);
    pos += size;
    if (pos & 1)
      pos++;
  }
}


x86 assembly (clang, -O0):
<process_library>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e81(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1060 <xfseek@plt>
mov    -0x10(%rbp),%rcx
lea    0x2ecd(%rip),%rdi
mov    $0x10,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x0,%rax
jne    11a1 <process_library+0x51>
jmp    1236 <process_library+0xe6>
mov    0x2ea8(%rip),%rax
cmpl   $0x60,(%rax)
jne    11c2 <process_library+0x72>
mov    0x2e98(%rip),%rax
cmpl   $0xa,0x4(%rax)
je     11c7 <process_library+0x77>
jmp    1236 <process_library+0xe6>
mov    0x2e8b(%rip),%edi
call   1070 <atol@plt>
mov    %rax,-0x20(%rbp)
movslq -0x14(%rbp),%rax
add    $0x10,%rax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x8(%rbp),%rsi
call   1050 <have_object@plt>
cmp    $0x0,%eax
jne    120b <process_library+0xbb>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x8(%rbp),%rcx
mov    $0x1,%edx
call   1040 <load_object@plt>
mov    -0x20(%rbp),%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1231 <process_library+0xe1>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    116c <process_library+0x1c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_library>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r12
mov    %rdi,%r14
mov    0x2e83(%rip),%rax
mov    (%rax),%ebp
mov    %rsi,%rdi
mov    %ebp,%esi
call   1060 <xfseek@plt>
lea    0x2ed8(%rip),%rdi
mov    $0x10,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1030 <fread@plt>
test   %rax,%rax
je     1212 <process_library+0xc2>
lea    0x2eb6(%rip),%r15
jmp    11cd <process_library+0x7d>
nopl   0x0(%rax)
add    %ebx,%ebp
mov    %ebp,%eax
and    $0x1,%eax
add    %eax,%ebp
mov    %r12,%rdi
mov    %ebp,%esi
call   1060 <xfseek@plt>
mov    %r15,%rdi
mov    $0x10,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1030 <fread@plt>
test   %rax,%rax
je     1212 <process_library+0xc2>
mov    0x2e7c(%rip),%rax
cmpl   $0x60,(%rax)
jne    1212 <process_library+0xc2>
cmpl   $0xa,0x4(%rax)
jne    1212 <process_library+0xc2>
mov    0x2e73(%rip),%edi
call   1070 <atol@plt>
mov    %rax,%rbx
add    $0x10,%ebp
mov    %ebp,%edi
mov    %r14,%rsi
call   1050 <have_object@plt>
test   %eax,%eax
jne    11a0 <process_library+0x50>
mov    %r12,%rdi
mov    %ebp,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1040 <load_object@plt>
jmp    11a0 <process_library+0x50>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ar_hdr = type { i32*, i32 }
@process_library.ah = internal global %struct.ar_hdr zeroinitializer
@SARMAG = global i32 0
define void @process_library(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i64
store i8* %0, i8** %3
store i32* %1, i32** %4
%7 = load i32, i32* @SARMAG
store i32 %7, i32* %5
br label %8
8: ; preds = %2, %55
%9 = load i32*, i32** %4
%10 = load i32, i32* %5
%11 = call i32 @xfseek(i32* %9, i32 %10)
%12 = load i32*, i32** %4
%13 = call i64 @fread(%struct.ar_hdr* @process_library.ah, i32 16, i32 1, i32* %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %8
br label %56
16: ; preds = %8
%17 = load i32*, i32** getelementptr inbounds (%struct.ar_hdr, %struct.ar_hdr* @process_library.ah, i32 0, i32 0)
%18 = getelementptr inbounds i32, i32* %17, i64 0
%19 = load i32, i32* %18
%20 = icmp ne i32 %19, 96
br i1 %20, label %26, label %21
21: ; preds = %16
%22 = load i32*, i32** getelementptr inbounds (%struct.ar_hdr, %struct.ar_hdr* @process_library.ah, i32 0, i32 0)
%23 = getelementptr inbounds i32, i32* %22, i64 1
%24 = load i32, i32* %23
%25 = icmp ne i32 %24, 10
br i1 %25, label %26, label %27
26: ; preds = %21, %16
br label %56
27: ; preds = %21
%28 = load i32, i32* getelementptr inbounds (%struct.ar_hdr, %struct.ar_hdr* @process_library.ah, i32 0, i32 1)
%29 = call i64 @atol(i32 %28)
store i64 %29, i64* %6
%30 = load i32, i32* %5
%31 = sext i32 %30 to i64
%32 = add i64 %31, 16
%33 = trunc i64 %32 to i32
store i32 %33, i32* %5
%34 = load i32, i32* %5
%35 = load i8*, i8** %3
%36 = call i32 @have_object(i32 %34, i8* %35)
%37 = icmp ne i32 %36, 0
br i1 %37, label %43, label %38
38: ; preds = %27
%39 = load i32*, i32** %4
%40 = load i32, i32* %5
%41 = load i8*, i8** %3
%42 = call i32 @load_object(i32* %39, i32 %40, i32 1, i8* %41)
br label %43
43: ; preds = %38, %27
%44 = load i64, i64* %6
%45 = load i32, i32* %5
%46 = sext i32 %45 to i64
%47 = add i64 %46, %44
%48 = trunc i64 %47 to i32
store i32 %48, i32* %5
%49 = load i32, i32* %5
%50 = and i32 %49, 1
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %43
%53 = load i32, i32* %5
%54 = add nsw i32 %53, 1
store i32 %54, i32* %5
br label %55
55: ; preds = %52, %43
br label %8
56: ; preds = %26, %15
ret void
}

LLVM IR (-O2):
%struct.ar_hdr = type { i32*, i32 }
@process_library.ah = internal global %struct.ar_hdr zeroinitializer
@SARMAG = global i32 0
define void @process_library(i8* %0, i32* %1) {
%3 = load i32, i32* @SARMAG
%4 = tail call i32 @xfseek(i32* %1, i32 %3)
%5 = tail call i64 @fread(%struct.ar_hdr* @process_library.ah, i32 16, i32 1, i32* %1)
%6 = icmp eq i64 %5, 0
br i1 %6, label %32, label %7
7: ; preds = %2, %24
%8 = phi i32 [ %28, %24 ], [ %3, %2 ]
%9 = load i32*, i32** getelementptr inbounds (%struct.ar_hdr, %struct.ar_hdr* @process_library.ah, i64 0, i32 0)
%10 = load i32, i32* %9
%11 = icmp eq i32 %10, 96
br i1 %11, label %12, label %32
12: ; preds = %7
%13 = getelementptr inbounds i32, i32* %9, i64 1
%14 = load i32, i32* %13
%15 = icmp eq i32 %14, 10
br i1 %15, label %16, label %32
16: ; preds = %12
%17 = load i32, i32* getelementptr inbounds (%struct.ar_hdr, %struct.ar_hdr* @process_library.ah, i64 0, i32 1)
%18 = tail call i64 @atol(i32 %17)
%19 = add i32 %8, 16
%20 = tail call i32 @have_object(i32 %19, i8* %0)
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %16
%23 = tail call i32 @load_object(i32* %1, i32 %19, i32 1, i8* %0)
br label %24
24: ; preds = %22, %16
%25 = trunc i64 %18 to i32
%26 = add i32 %19, %25
%27 = and i32 %26, 1
%28 = add nsw i32 %27, %26
%29 = tail call i32 @xfseek(i32* %1, i32 %28)
%30 = tail call i64 @fread(%struct.ar_hdr* @process_library.ah, i32 16, i32 1, i32* %1)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %7
32: ; preds = %24, %12, %7, %2
ret void
}