#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 */
char Dat1Check(char *);
char Dat2Check(char *);
char DatXCheck(char *);
int FR_popcnt(char);
int /*<<< orphan*/ printf(char *, int);
char IdentifyDat(char *path) {
  char version = Dat1Check(path) | Dat2Check(path) | DatXCheck(path);
  printf("Detected version: %i\n", (int)version);
  if (FR_popcnt(version & 7) > 1)
    return -32;
  else
    return version;
}


x86 assembly (clang, -O0):
<IdentifyDat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <Dat1Check@plt>
movsbl %al,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <Dat2Check@plt>
mov    %al,%cl
mov    -0x1c(%rbp),%eax
movsbl %cl,%ecx
or     %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <DatXCheck@plt>
mov    %al,%cl
mov    -0x18(%rbp),%eax
movsbl %cl,%ecx
or     %ecx,%eax
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%esi
lea    0xe5e(%rip),%rdi
call   1050 <printf@plt>
movsbl -0x11(%rbp),%eax
and    $0x7,%eax
movsbl %al,%edi
call   1040 <FR_popcnt@plt>
cmp    $0x1,%eax
jle    11c8 <IdentifyDat+0x78>
movb   $0xe0,-0x1(%rbp)
jmp    11ce <IdentifyDat+0x7e>
mov    -0x11(%rbp),%al
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<IdentifyDat>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbp
call   1070 <Dat1Check@plt>
mov    %eax,%r14d
mov    %rbp,%rdi
call   1030 <Dat2Check@plt>
mov    %eax,%ebx
or     %r14b,%bl
mov    %rbp,%rdi
call   1060 <DatXCheck@plt>
or     %bl,%al
movsbl %al,%ebx
lea    0xe80(%rip),%rdi
mov    %ebx,%esi
call   1050 <printf@plt>
mov    %ebx,%eax
and    $0x7,%al
movzbl %al,%edi
call   1040 <FR_popcnt@plt>
cmp    $0x2,%eax
movzbl %bl,%ecx
mov    $0xe0,%eax
cmovl  %ecx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Detected version: %i\0A\00"
define signext i8 @IdentifyDat(i8* %0) {
%2 = alloca i8
%3 = alloca i8*
%4 = alloca i8
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call signext i8 @Dat1Check(i8* %5)
%7 = sext i8 %6 to i32
%8 = load i8*, i8** %3
%9 = call signext i8 @Dat2Check(i8* %8)
%10 = sext i8 %9 to i32
%11 = or i32 %7, %10
%12 = load i8*, i8** %3
%13 = call signext i8 @DatXCheck(i8* %12)
%14 = sext i8 %13 to i32
%15 = or i32 %11, %14
%16 = trunc i32 %15 to i8
store i8 %16, i8* %4
%17 = load i8, i8* %4
%18 = sext i8 %17 to i32
%19 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = load i8, i8* %4
%21 = sext i8 %20 to i32
%22 = and i32 %21, 7
%23 = trunc i32 %22 to i8
%24 = call i32 @FR_popcnt(i8 signext %23)
%25 = icmp sgt i32 %24, 1
br i1 %25, label %26, label %27
26: ; preds = %1
store i8 -32, i8* %2
br label %29
27: ; preds = %1
%28 = load i8, i8* %4
store i8 %28, i8* %2
br label %29
29: ; preds = %27, %26
%30 = load i8, i8* %2
ret i8 %30
}

LLVM IR (-O2):
@.str = [22 x i8] c"Detected version: %i\0A\00"
define signext i8 @IdentifyDat(i8* %0) {
%2 = tail call signext i8 @Dat1Check(i8* %0)
%3 = tail call signext i8 @Dat2Check(i8* %0)
%4 = or i8 %3, %2
%5 = tail call signext i8 @DatXCheck(i8* %0)
%6 = or i8 %4, %5
%7 = sext i8 %6 to i32
%8 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = and i8 %6, 7
%10 = tail call i32 @FR_popcnt(i8 signext %9)
%11 = icmp sgt i32 %10, 1
%12 = select i1 %11, i8 -32, i8 %6
ret i8 %12
}