#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 {
  char *ar_fmag;
  char *ar_name;
  char *ar_size;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
char *ARFMAG;
char *ARMAG;
int SARMAG;
int /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char const *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
size_t strlen(char *);
scalar_t__ strncmp(char *, char *, size_t);
char *strrchr(char *, char);
scalar_t__ strtol(char *, int /*<<< orphan*/ *, int);
FILE *ArchFindMember(char *archive, char *member, struct ar_hdr *arhPtr,
                     const char *mode) {
  FILE *arch;
  int size;
  char *cp;
  char magic[SARMAG];
  size_t len, tlen;
  arch = fopen(archive, mode);
  if (arch == NULL) {
    return NULL;
  }
  if ((fread(magic, SARMAG, 1, arch) != 1) ||
      (strncmp(magic, ARMAG, SARMAG) != 0)) {
    fclose(arch);
    return NULL;
  }
  cp = strrchr(member, '/');
  if (cp != NULL) {
    member = cp + 1;
  }
  len = tlen = strlen(member);
  if (len > sizeof(arhPtr->ar_name)) {
    tlen = sizeof(arhPtr->ar_name);
  }
  while (fread((char *)arhPtr, sizeof(struct ar_hdr), 1, arch) == 1) {
    if (strncmp(arhPtr->ar_fmag, ARFMAG, sizeof(arhPtr->ar_fmag)) != 0) {
      fclose(arch);
      return NULL;
    } else if (strncmp(member, arhPtr->ar_name, tlen) == 0) {
      if (tlen != sizeof(arhPtr->ar_name) && arhPtr->ar_name[tlen] != ' ') {
        goto skip;
      } else {
        fseek(arch, -sizeof(struct ar_hdr), SEEK_CUR);
        return (arch);
      }
    } else {
    skip:
      arhPtr->ar_size[sizeof(arhPtr->ar_size) - 1] = '\0';
      size = (int)strtol(arhPtr->ar_size, NULL, 10);
      fseek(arch, (size + 1) & ~1, SEEK_CUR);
    }
  }
  fclose(arch);
  return NULL;
}


x86 assembly (clang, -O0):
<ArchFindMember>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    0x2e39(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x70(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11f4 <ArchFindMember+0x74>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x64(%rbp)
jmp    13ea <ArchFindMember+0x26a>
mov    -0x70(%rbp),%rdi
mov    0x2dd9(%rip),%rax
mov    (%rax),%esi
mov    -0x30(%rbp),%rcx
mov    $0x1,%edx
call   1040 <fread@plt>
cmp    $0x1,%eax
jne    123f <ArchFindMember+0xbf>
mov    -0x70(%rbp),%rdi
mov    0x2d9d(%rip),%rax
mov    (%rax),%rsi
mov    0x2dab(%rip),%rax
movslq (%rax),%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     125c <ArchFindMember+0xdc>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x64(%rbp)
jmp    13ea <ArchFindMember+0x26a>
mov    -0x18(%rbp),%rdi
mov    $0x2f,%esi
call   1070 <strrchr@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     1285 <ArchFindMember+0x105>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,-0x60(%rbp)
mov    %rax,-0x58(%rbp)
cmpq   $0x8,-0x58(%rbp)
jbe    12a9 <ArchFindMember+0x129>
movq   $0x8,-0x60(%rbp)
jmp    12ae <ArchFindMember+0x12e>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rcx
mov    $0x18,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
cmp    $0x1,%eax
jne    13d2 <ArchFindMember+0x252>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
mov    0x2d14(%rip),%rax
mov    (%rax),%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     1310 <ArchFindMember+0x190>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x64(%rbp)
jmp    13ea <ArchFindMember+0x26a>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x60(%rbp),%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1383 <ArchFindMember+0x203>
cmpq   $0x8,-0x60(%rbp)
je     1358 <ArchFindMember+0x1d8>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x60(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
je     1358 <ArchFindMember+0x1d8>
jmp    1388 <ArchFindMember+0x208>
mov    -0x30(%rbp),%rdi
mov    0x2c7d(%rip),%rax
mov    (%rax),%edx
mov    $0xffffffe8,%esi
call   1090 <fseek@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x64(%rbp)
jmp    13ea <ArchFindMember+0x26a>
jmp    1388 <ArchFindMember+0x208>
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%rax
movb   $0x0,0x7(%rax)
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1080 <strtol@plt>
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%esi
add    $0x1,%esi
and    $0xfffffffe,%esi
mov    0x2c1f(%rip),%rax
mov    (%rax),%edx
call   1090 <fseek@plt>
jmp    13cd <ArchFindMember+0x24d>
jmp    12ae <ArchFindMember+0x12e>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x64(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ArchFindMember>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r12
mov    0x2e3d(%rip),%r13
mov    0x0(%r13),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rcx,%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     11fc <ArchFindMember+0x7c>
mov    %rax,%r15
mov    0x0(%r13),%esi
mov    %rbx,%rdi
mov    $0x1,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
cmp    $0x1,%eax
jne    11f4 <ArchFindMember+0x74>
mov    0x2de0(%rip),%rax
mov    (%rax),%rsi
movslq 0x0(%r13),%rdx
mov    %rbx,%rdi
call   1030 <strncmp@plt>
test   %rax,%rax
je     1211 <ArchFindMember+0x91>
mov    %r15,%rdi
call   1050 <fclose@plt>
xor    %r15d,%r15d
mov    %r15,%rax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r12,%rdi
mov    $0x2f,%esi
call   1070 <strrchr@plt>
lea    0x1(%rax),%rbx
test   %rax,%rax
cmove  %r12,%rbx
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %rax,%r12
cmp    $0x8,%rax
mov    $0x8,%r13d
cmovb  %rax,%r13
jmp    127f <ArchFindMember+0xff>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x10(%r14),%rax
movb   $0x0,0x7(%rax)
mov    0x10(%r14),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1080 <strtol@plt>
lea    0x1(%rax),%esi
and    $0xfffffffe,%esi
mov    0x2d6b(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
call   1090 <fseek@plt>
mov    %r14,%rdi
mov    $0x18,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1040 <fread@plt>
cmp    $0x1,%eax
jne    11f4 <ArchFindMember+0x74>
mov    (%r14),%rdi
mov    0x2d49(%rip),%rax
mov    (%rax),%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    11f4 <ArchFindMember+0x74>
mov    0x8(%r14),%rsi
mov    %rbx,%rdi
mov    %r13,%rdx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1250 <ArchFindMember+0xd0>
cmp    $0x7,%r12
ja     12ea <ArchFindMember+0x16a>
mov    0x8(%r14),%rax
cmpb   $0x20,(%rax,%r13,1)
jne    1250 <ArchFindMember+0xd0>
mov    0x2cef(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
mov    $0xffffffe8,%esi
call   1090 <fseek@plt>
jmp    11ff <ArchFindMember+0x7f>

LLVM IR (-O0):
%struct.ar_hdr = type { i8*, i8*, i8* }
@SARMAG = global i32 0
@ARMAG = global i8* null
@ARFMAG = global i8* null
@SEEK_CUR = global i32 0
define i32* @ArchFindMember(i8* %0, i8* %1, %struct.ar_hdr* %2, i8* %3) {
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca %struct.ar_hdr*
%9 = alloca i8*
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i64
%15 = alloca i64
%16 = alloca i64
%17 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store %struct.ar_hdr* %2, %struct.ar_hdr** %8
store i8* %3, i8** %9
%18 = load i32, i32* @SARMAG
%19 = zext i32 %18 to i64
%20 = call i8* @llvm.stacksave()
store i8* %20, i8** %13
%21 = alloca i8, i64 %19
store i64 %19, i64* %14
%22 = load i8*, i8** %6
%23 = load i8*, i8** %9
%24 = call i32* @fopen(i8* %22, i8* %23)
store i32* %24, i32** %10
%25 = load i32*, i32** %10
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %28
27: ; preds = %4
store i32* null, i32** %5
store i32 1, i32* %17
br label %121
28: ; preds = %4
%29 = load i32, i32* @SARMAG
%30 = load i32*, i32** %10
%31 = call i32 @fread(i8* %21, i32 %29, i32 1, i32* %30)
%32 = icmp ne i32 %31, 1
br i1 %32, label %39, label %33
33: ; preds = %28
%34 = load i8*, i8** @ARMAG
%35 = load i32, i32* @SARMAG
%36 = sext i32 %35 to i64
%37 = call i64 @strncmp(i8* %21, i8* %34, i64 %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %33, %28
%40 = load i32*, i32** %10
%41 = call i32 @fclose(i32* %40)
store i32* null, i32** %5
store i32 1, i32* %17
br label %121
42: ; preds = %33
%43 = load i8*, i8** %7
%44 = call i8* @strrchr(i8* %43, i8 signext 47)
store i8* %44, i8** %12
%45 = load i8*, i8** %12
%46 = icmp ne i8* %45, null
br i1 %46, label %47, label %50
47: ; preds = %42
%48 = load i8*, i8** %12
%49 = getelementptr inbounds i8, i8* %48, i64 1
store i8* %49, i8** %7
br label %50
50: ; preds = %47, %42
%51 = load i8*, i8** %7
%52 = call i64 @strlen(i8* %51)
store i64 %52, i64* %16
store i64 %52, i64* %15
%53 = load i64, i64* %15
%54 = icmp ugt i64 %53, 8
br i1 %54, label %55, label %56
55: ; preds = %50
store i64 8, i64* %16
br label %56
56: ; preds = %55, %50
br label %57
57: ; preds = %117, %56
%58 = load %struct.ar_hdr*, %struct.ar_hdr** %8
%59 = bitcast %struct.ar_hdr* %58 to i8*
%60 = load i32*, i32** %10
%61 = call i32 @fread(i8* %59, i32 24, i32 1, i32* %60)
%62 = icmp eq i32 %61, 1
br i1 %62, label %63, label %118
63: ; preds = %57
%64 = load %struct.ar_hdr*, %struct.ar_hdr** %8
%65 = getelementptr inbounds %struct.ar_hdr, %struct.ar_hdr* %64, i32 0, i32 0
%66 = load i8*, i8** %65
%67 = load i8*, i8** @ARFMAG
%68 = call i64 @strncmp(i8* %66, i8* %67, i64 8)
%69 = icmp ne i64 %68, 0
br i1 %69, label %70, label %73
70: ; preds = %63
%71 = load i32*, i32** %10
%72 = call i32 @fclose(i32* %71)
store i32* null, i32** %5
store i32 1, i32* %17
br label %121
73: ; preds = %63
%74 = load i8*, i8** %7
%75 = load %struct.ar_hdr*, %struct.ar_hdr** %8
%76 = getelementptr inbounds %struct.ar_hdr, %struct.ar_hdr* %75, i32 0, i32 1
%77 = load i8*, i8** %76
%78 = load i64, i64* %16
%79 = call i64 @strncmp(i8* %74, i8* %77, i64 %78)
%80 = icmp eq i64 %79, 0
br i1 %80, label %81, label %99
81: ; preds = %73
%82 = load i64, i64* %16
%83 = icmp ne i64 %82, 8
br i1 %83, label %84, label %94
84: ; preds = %81
%85 = load %struct.ar_hdr*, %struct.ar_hdr** %8
%86 = getelementptr inbounds %struct.ar_hdr, %struct.ar_hdr* %85, i32 0, i32 1
%87 = load i8*, i8** %86
%88 = load i64, i64* %16
%89 = getelementptr inbounds i8, i8* %87, i64 %88
%90 = load i8, i8* %89
%91 = sext i8 %90 to i32
%92 = icmp ne i32 %91, 32
br i1 %92, label %93, label %94
93: ; preds = %84
br label %100
94: ; preds = %84, %81
%95 = load i32*, i32** %10
%96 = load i32, i32* @SEEK_CUR
%97 = call i32 @fseek(i32* %95, i32 -24, i32 %96)
%98 = load i32*, i32** %10
store i32* %98, i32** %5
store i32 1, i32* %17
br label %121
99: ; preds = %73
br label %100
100: ; preds = %99, %93
%101 = load %struct.ar_hdr*, %struct.ar_hdr** %8
%102 = getelementptr inbounds %struct.ar_hdr, %struct.ar_hdr* %101, i32 0, i32 2
%103 = load i8*, i8** %102
%104 = getelementptr inbounds i8, i8* %103, i64 7
store i8 0, i8* %104
%105 = load %struct.ar_hdr*, %struct.ar_hdr** %8
%106 = getelementptr inbounds %struct.ar_hdr, %struct.ar_hdr* %105, i32 0, i32 2
%107 = load i8*, i8** %106
%108 = call i64 @strtol(i8* %107, i32* null, i32 10)
%109 = trunc i64 %108 to i32
store i32 %109, i32* %11
%110 = load i32*, i32** %10
%111 = load i32, i32* %11
%112 = add nsw i32 %111, 1
%113 = and i32 %112, -2
%114 = load i32, i32* @SEEK_CUR
%115 = call i32 @fseek(i32* %110, i32 %113, i32 %114)
br label %116
116: ; preds = %100
br label %117
117: ; preds = %116
br label %57
118: ; preds = %57
%119 = load i32*, i32** %10
%120 = call i32 @fclose(i32* %119)
store i32* null, i32** %5
store i32 1, i32* %17
br label %121
121: ; preds = %118, %94, %70, %39, %27
%122 = load i8*, i8** %13
%123 = load i32*, i32** %5
ret i32* %123
}

LLVM IR (-O2):
%struct.ar_hdr = type { i8*, i8*, i8* }
@SARMAG = global i32 0
@ARMAG = global i8* null
@ARFMAG = global i8* null
@SEEK_CUR = global i32 0
define noalias i32* @ArchFindMember(i8* nocapture %0, i8* %1, %struct.ar_hdr* nocapture %2, i8* nocapture %3) {
%5 = load i32, i32* @SARMAG
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = tail call i32* @fopen(i8* %0, i8* %3)
%9 = icmp eq i32* %8, null
br i1 %9, label %72, label %10
10: ; preds = %4
%11 = load i32, i32* @SARMAG
%12 = call i32 @fread(i8* %7, i32 %11, i32 1, i32* %8)
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %20
14: ; preds = %10
%15 = load i8*, i8** @ARMAG
%16 = load i32, i32* @SARMAG
%17 = sext i32 %16 to i64
%18 = call i64 @strncmp(i8* %7, i8* %15, i64 %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %14, %10
%21 = call i32 @fclose(i32* %8)
br label %72
22: ; preds = %14
%23 = call i8* @strrchr(i8* dereferenceable(1) %1, i8 signext 47)
%24 = icmp eq i8* %23, null
%25 = getelementptr inbounds i8, i8* %23, i64 1
%26 = select i1 %24, i8* %1, i8* %25
%27 = call i64 @strlen(i8* dereferenceable(1) %26)
%28 = icmp ult i64 %27, 8
%29 = select i1 %28, i64 %27, i64 8
%30 = bitcast %struct.ar_hdr* %2 to i8*
%31 = call i32 @fread(i8* %30, i32 24, i32 1, i32* %8)
%32 = icmp eq i32 %31, 1
br i1 %32, label %33, label %70
33: ; preds = %22
%34 = getelementptr inbounds %struct.ar_hdr, %struct.ar_hdr* %2, i64 0, i32 0
%35 = getelementptr inbounds %struct.ar_hdr, %struct.ar_hdr* %2, i64 0, i32 1
%36 = icmp ugt i64 %27, 7
%37 = getelementptr inbounds %struct.ar_hdr, %struct.ar_hdr* %2, i64 0, i32 2
br label %38
38: ; preds = %33, %58
%39 = load i8*, i8** %34
%40 = load i8*, i8** @ARFMAG
%41 = call i64 @strncmp(i8* %39, i8* %40, i64 8)
%42 = icmp eq i64 %41, 0
br i1 %42, label %45, label %43
43: ; preds = %38
%44 = call i32 @fclose(i32* %8)
br label %72
45: ; preds = %38
%46 = load i8*, i8** %35
%47 = call i64 @strncmp(i8* %26, i8* %46, i64 %29)
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %58
49: ; preds = %45
br i1 %36, label %55, label %50
50: ; preds = %49
%51 = load i8*, i8** %35
%52 = getelementptr inbounds i8, i8* %51, i64 %29
%53 = load i8, i8* %52
%54 = icmp eq i8 %53, 32
br i1 %54, label %55, label %58
55: ; preds = %50, %49
%56 = load i32, i32* @SEEK_CUR
%57 = call i32 @fseek(i32* %8, i32 -24, i32 %56)
br label %72
58: ; preds = %45, %50
%59 = load i8*, i8** %37
%60 = getelementptr inbounds i8, i8* %59, i64 7
store i8 0, i8* %60
%61 = load i8*, i8** %37
%62 = call i64 @strtol(i8* nocapture %61, i32* null, i32 10)
%63 = trunc i64 %62 to i32
%64 = add nsw i32 %63, 1
%65 = and i32 %64, -2
%66 = load i32, i32* @SEEK_CUR
%67 = call i32 @fseek(i32* %8, i32 %65, i32 %66)
%68 = call i32 @fread(i8* %30, i32 24, i32 1, i32* %8)
%69 = icmp eq i32 %68, 1
br i1 %69, label %38, label %70
70: ; preds = %58, %22
%71 = call i32 @fclose(i32* %8)
br label %72
72: ; preds = %4, %70, %55, %43, %20
%73 = phi i32* [ null, %20 ], [ null, %43 ], [ %8, %55 ], [ null, %70 ], [ null, %4 ]
ret i32* %73
}