#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 /*<<< orphan*/ ar_fmag;
};

/* Variables and functions */
int /*<<< orphan*/ ARFMAG;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char const *,
                           char *);
scalar_t__ memcmp(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
int _do_hdr_check(char const *archive, struct ar_hdr *hdr) {
  if (memcmp(ARFMAG, hdr->ar_fmag, sizeof(hdr->ar_fmag)) != 0) {
    fprintf(stderr, "%s%s%s",
            "ar"
            ": ",
            archive, ": Invalid archive\n");
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<_do_hdr_check>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2eb9(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
mov    $0x4,%edx
call   1030 <memcmp@plt>
cmp    $0x0,%rax
je     1186 <_do_hdr_check+0x66>
mov    0x2e7e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rcx
lea    0xe99(%rip),%rsi
lea    0xe99(%rip),%rdx
lea    0xe97(%rip),%r8
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    118d <_do_hdr_check+0x6d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_do_hdr_check>:
push   %rbx
mov    %rdi,%rbx
mov    0x2ec5(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%esi
mov    $0x4,%edx
call   1030 <memcmp@plt>
test   %rax,%rax
je     116b <_do_hdr_check+0x4b>
mov    0x2e93(%rip),%rax
mov    (%rax),%edi
lea    0xeb2(%rip),%rsi
lea    0xeb2(%rip),%rdx
lea    0xeb0(%rip),%r8
mov    %rbx,%rcx
call   1040 <fprintf@plt>
mov    $0x1,%eax
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.ar_hdr = type { i32 }
@ARFMAG = global i32 0
@stderr = global i32 0
@.str = [7 x i8] c"%s%s%s\00"
@.str.1 = [5 x i8] c"ar: \00"
@.str.2 = [19 x i8] c": Invalid archive\0A\00"
define i32 @_do_hdr_check(i8* %0, %struct.ar_hdr* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.ar_hdr*
store i8* %0, i8** %4
store %struct.ar_hdr* %1, %struct.ar_hdr** %5
%6 = load i32, i32* @ARFMAG
%7 = load %struct.ar_hdr*, %struct.ar_hdr** %5
%8 = getelementptr inbounds %struct.ar_hdr, %struct.ar_hdr* %7, i32 0, i32 0
%9 = load i32, i32* %8
%10 = call i64 @memcmp(i32 %6, i32 %9, i32 4)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %4
%15 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %14, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %17
16: ; preds = %2
store i32 0, i32* %3
br label %17
17: ; preds = %16, %12
%18 = load i32, i32* %3
ret i32 %18
}

LLVM IR (-O2):
%struct.ar_hdr = type { i32 }
@ARFMAG = global i32 0
@stderr = global i32 0
@.str = [7 x i8] c"%s%s%s\00"
@.str.1 = [5 x i8] c"ar: \00"
@.str.2 = [19 x i8] c": Invalid archive\0A\00"
define i32 @_do_hdr_check(i8* %0, %struct.ar_hdr* nocapture %1) {
%3 = load i32, i32* @ARFMAG
%4 = getelementptr inbounds %struct.ar_hdr, %struct.ar_hdr* %1, i64 0, i32 0
%5 = load i32, i32* %4
%6 = tail call i64 @memcmp(i32 %3, i32 %5, i32 4)
%7 = icmp eq i64 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %11
11: ; preds = %2, %8
%12 = phi i32 [ 1, %8 ], [ 0, %2 ]
ret i32 %12
}