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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ err(int, int /*<<< orphan*/ *, ...);
int /*<<< orphan*/ errno;
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
scalar_t__ strcmp(char *, char *);
void check_archive(char *ar_name) {
  int fd;
  char str[8 + 1];
  if ((fd = open(ar_name, O_RDONLY)) == -1)
    goto error;
  if (read(fd, str, 8) == -1)
    goto close;
  if (strcmp(str, "!<arch>\n") != 0)
    err(1, 0, "%s: %s: File format not recognized\n");
close:
  close(fd);
  return;
error:
  err(errno, NULL);
  return;
}


x86 assembly (clang, -O0):
<check_archive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e81(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0xc(%rbp)
cmp    $0xffffffff,%eax
jne    117f <check_archive+0x2f>
jmp    11e1 <check_archive+0x91>
mov    -0xc(%rbp),%edi
lea    -0x15(%rbp),%rsi
mov    $0x8,%edx
call   1040 <read@plt>
cmp    $0xffffffff,%eax
jne    119e <check_archive+0x4e>
jmp    11d4 <check_archive+0x84>
lea    -0x15(%rbp),%rdi
lea    0xe57(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     11cf <check_archive+0x7f>
mov    $0x1,%edi
xor    %eax,%eax
mov    %eax,%esi
lea    0xe41(%rip),%rdx
mov    $0x0,%al
call   1060 <err@plt>
jmp    11d4 <check_archive+0x84>
mov    -0xc(%rbp),%edi
call   1030 <close@plt>
jmp    11f5 <check_archive+0xa5>
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x0,%al
call   1060 <err@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_archive>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e8c(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     11b8 <check_archive+0x68>
mov    %eax,%ebx
lea    0x7(%rsp),%rsi
mov    %eax,%edi
mov    $0x8,%edx
call   1040 <read@plt>
cmp    $0xffffffff,%eax
je     11ab <check_archive+0x5b>
lea    0xe79(%rip),%rsi
lea    0x7(%rsp),%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11ab <check_archive+0x5b>
lea    0xe6c(%rip),%rdx
mov    $0x1,%edi
xor    %esi,%esi
xor    %eax,%eax
call   1060 <err@plt>
mov    %ebx,%edi
call   1030 <close@plt>
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
jmp    1060 <err@plt>

LLVM IR (-O0):
@O_RDONLY = global i32 0
@.str = [9 x i8] c"!<arch>\0A\00"
@.str.1 = [36 x i8] c"%s: %s: File format not recognized\0A\00"
@errno = global i32 0
define void @check_archive(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [9 x i8]
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = load i32, i32* @O_RDONLY
%7 = call i32 @open(i8* %5, i32 %6)
store i32 %7, i32* %3
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %10
9: ; preds = %1
br label %26
10: ; preds = %1
%11 = load i32, i32* %3
%12 = getelementptr inbounds [9 x i8], [9 x i8]* %4, i64 0, i64 0
%13 = call i32 @read(i32 %11, i8* %12, i32 8)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %16
15: ; preds = %10
br label %23
16: ; preds = %10
%17 = getelementptr inbounds [9 x i8], [9 x i8]* %4, i64 0, i64 0
%18 = call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = call i32 (i32, i32*, ...) @err(i32 1, i32* null, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %20, %16
br label %23
23: ; preds = %22, %15
%24 = load i32, i32* %3
%25 = call i32 @close(i32 %24)
br label %29
26: ; preds = %9
%27 = load i32, i32* @errno
%28 = call i32 (i32, i32*, ...) @err(i32 %27, i32* null)
br label %29
29: ; preds = %26, %23
ret void
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str = [9 x i8] c"!<arch>\0A\00"
@.str.1 = [36 x i8] c"%s: %s: File format not recognized\0A\00"
@errno = global i32 0
define void @check_archive(i8* nocapture %0) {
%2 = alloca [9 x i8]
%3 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 @open(i8* %0, i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %17, label %7
7: ; preds = %1
%8 = call i32 @read(i32 %5, i8* %3, i32 8)
%9 = icmp eq i32 %8, -1
br i1 %9, label %15, label %10
10: ; preds = %7
%11 = call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = call i32 (i32, i32*, ...) @err(i32 1, i32* null, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %10, %13, %7
%16 = call i32 @close(i32 %5)
br label %20
17: ; preds = %1
%18 = load i32, i32* @errno
%19 = tail call i32 (i32, i32*, ...) @err(i32 %18, i32* null)
br label %20
20: ; preds = %17, %15
ret void
}