#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 */
typedef int /*<<< orphan*/ sig;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ ARMAG;
int SARMAG;
int _ar_error(char const *, int);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char const *,
                           char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
scalar_t__ memcmp(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stderr;
int _do_sig_check(char const *archive, FILE *fp) {
  char sig[SARMAG];
  if (fread(sig, sizeof(sig), 1, fp) != 1 && !feof(fp))
    return _ar_error(archive, 1);
  if (memcmp(ARMAG, sig, sizeof(sig)) == 0)
    return 0;
  fprintf(stderr, "%s%s%s",
          "ar"
          ": ",
          archive, ": Invalid archive\n");
  return 1;
}


x86 assembly (clang, -O0):
<_do_sig_check>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2e81(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x40(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
mov    %eax,%esi
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x1,%eax
je     11d8 <_do_sig_check+0x88>
mov    -0x18(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
jne    11d8 <_do_sig_check+0x88>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1070 <_ar_error@plt>
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    1242 <_do_sig_check+0xf2>
mov    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%rax
mov    0x2de1(%rip),%rcx
mov    (%rcx),%edi
mov    %eax,%edx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
jne    120d <_do_sig_check+0xbd>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    1242 <_do_sig_check+0xf2>
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rcx
lea    0xddf(%rip),%rsi
lea    0xddf(%rip),%rdx
lea    0xddd(%rip),%r8
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_do_sig_check>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r12
mov    %rdi,%r14
mov    0x2e80(%rip),%rax
mov    (%rax),%r15d
mov    %rsp,%rbx
mov    %r15,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %r15d,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1030 <fread@plt>
cmp    $0x1,%eax
je     11a3 <_do_sig_check+0x53>
mov    %r12,%rdi
call   1060 <feof@plt>
test   %eax,%eax
je     11f8 <_do_sig_check+0xa8>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1040 <memcmp@plt>
test   %rax,%rax
je     11e9 <_do_sig_check+0x99>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
lea    0xe34(%rip),%rsi
lea    0xe34(%rip),%rdx
lea    0xe32(%rip),%r8
mov    %r14,%rcx
call   1050 <fprintf@plt>
mov    $0x1,%eax
jmp    11eb <_do_sig_check+0x9b>
xor    %eax,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14,%rdi
mov    $0x1,%esi
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <_ar_error@plt>

LLVM IR (-O0):
@SARMAG = global i32 0
@ARMAG = 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_sig_check(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
%9 = load i32, i32* @SARMAG
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %6
%12 = alloca i8, i64 %10
store i64 %10, i64* %7
%13 = trunc i64 %10 to i32
%14 = load i32*, i32** %5
%15 = call i32 @fread(i8* %12, i32 %13, i32 1, i32* %14)
%16 = icmp ne i32 %15, 1
br i1 %16, label %17, label %24
17: ; preds = %2
%18 = load i32*, i32** %5
%19 = call i32 @feof(i32* %18)
%20 = icmp ne i32 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %17
%22 = load i8*, i8** %4
%23 = call i32 @_ar_error(i8* %22, i32 1)
store i32 %23, i32* %3
store i32 1, i32* %8
br label %34
24: ; preds = %17, %2
%25 = load i32, i32* @ARMAG
%26 = trunc i64 %10 to i32
%27 = call i64 @memcmp(i32 %25, i8* %12, i32 %26)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %24
store i32 0, i32* %3
store i32 1, i32* %8
br label %34
30: ; preds = %24
%31 = load i32, i32* @stderr
%32 = load i8*, i8** %4
%33 = call i32 @fprintf(i32 %31, 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* %32, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
store i32 1, i32* %8
br label %34
34: ; preds = %30, %29, %21
%35 = load i8*, i8** %6
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
@SARMAG = global i32 0
@ARMAG = 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_sig_check(i8* %0, i32* nocapture %1) {
%3 = load i32, i32* @SARMAG
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = call i32 @fread(i8* %5, i32 %3, i32 1, i32* %1)
%7 = icmp eq i32 %6, 1
br i1 %7, label %13, label %8
8: ; preds = %2
%9 = tail call i32 @feof(i32* %1)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 @_ar_error(i8* %0, i32 1)
br label %20
13: ; preds = %8, %2
%14 = load i32, i32* @ARMAG
%15 = call i64 @memcmp(i32 %14, i8* %5, i32 %3)
%16 = icmp eq i64 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %13
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, 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 %20
20: ; preds = %13, %17, %11
%21 = phi i32 [ 1, %17 ], [ %12, %11 ], [ 0, %13 ]
ret i32 %21
}