#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 uint8_t;

/* Variables and functions */
int des_getParityBitFromKey(int);
int /*<<< orphan*/ prnlog(char *, ...);
void des_checkParity(uint8_t *key) {
  int i;
  int fails = 0;
  for (i = 0; i < 8; i++) {
    bool parity = des_getParityBitFromKey(key[i]);
    if (parity != (key[i] & 0x1)) {
      fails++;
      prnlog("[+] parity1 fail, byte %d [%02x] was %d, should be %d", i, key[i],
             (key[i] & 0x1), parity);
    }
  }
  if (fails) {
    prnlog("[+] parity fails: %d", fails);
  } else {
    prnlog("[+] Key syntax is with parity bits inside each byte");
  }
}


x86 assembly (clang, -O0):
<des_checkParity>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x8,-0xc(%rbp)
jge    11ba <des_checkParity+0x9a>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1040 <des_getParityBitFromKey@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x8(%rbp),%rcx
movslq -0xc(%rbp),%rdx
mov    (%rcx,%rdx,4),%ecx
and    $0x1,%ecx
cmp    %ecx,%eax
je     11a7 <des_checkParity+0x87>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
and    $0x1,%ecx
mov    -0x14(%rbp),%r8d
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1030 <prnlog@plt>
jmp    11ac <des_checkParity+0x8c>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    113a <des_checkParity+0x1a>
cmpl   $0x0,-0x10(%rbp)
je     11da <des_checkParity+0xba>
mov    -0x10(%rbp),%esi
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1030 <prnlog@plt>
jmp    11e8 <des_checkParity+0xc8>
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1030 <prnlog@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<des_checkParity>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    (%rdi),%edi
call   1040 <des_getParityBitFromKey@plt>
mov    (%rbx),%edx
mov    %edx,%ecx
and    $0x1,%ecx
xor    %ebp,%ebp
cmp    %ecx,%eax
je     1152 <des_checkParity+0x32>
lea    0xebf(%rip),%rdi
xor    %esi,%esi
mov    %eax,%r8d
xor    %eax,%eax
call   1030 <prnlog@plt>
mov    $0x1,%ebp
mov    0x4(%rbx),%edi
call   1040 <des_getParityBitFromKey@plt>
mov    0x4(%rbx),%edx
mov    %edx,%ecx
and    $0x1,%ecx
cmp    %ecx,%eax
je     117f <des_checkParity+0x5f>
add    $0x1,%ebp
lea    0xe90(%rip),%rdi
mov    $0x1,%esi
mov    %eax,%r8d
xor    %eax,%eax
call   1030 <prnlog@plt>
mov    0x8(%rbx),%edi
call   1040 <des_getParityBitFromKey@plt>
mov    0x8(%rbx),%edx
mov    %edx,%ecx
and    $0x1,%ecx
cmp    %ecx,%eax
je     11ac <des_checkParity+0x8c>
add    $0x1,%ebp
lea    0xe63(%rip),%rdi
mov    $0x2,%esi
mov    %eax,%r8d
xor    %eax,%eax
call   1030 <prnlog@plt>
mov    0xc(%rbx),%edi
call   1040 <des_getParityBitFromKey@plt>
mov    0xc(%rbx),%edx
mov    %edx,%ecx
and    $0x1,%ecx
cmp    %ecx,%eax
je     11d9 <des_checkParity+0xb9>
add    $0x1,%ebp
lea    0xe36(%rip),%rdi
mov    $0x3,%esi
mov    %eax,%r8d
xor    %eax,%eax
call   1030 <prnlog@plt>
mov    0x10(%rbx),%edi
call   1040 <des_getParityBitFromKey@plt>
mov    0x10(%rbx),%edx
mov    %edx,%ecx
and    $0x1,%ecx
cmp    %ecx,%eax
je     1206 <des_checkParity+0xe6>
add    $0x1,%ebp
lea    0xe09(%rip),%rdi
mov    $0x4,%esi
mov    %eax,%r8d
xor    %eax,%eax
call   1030 <prnlog@plt>
mov    0x14(%rbx),%edi
call   1040 <des_getParityBitFromKey@plt>
mov    0x14(%rbx),%edx
mov    %edx,%ecx
and    $0x1,%ecx
cmp    %ecx,%eax
je     1233 <des_checkParity+0x113>
add    $0x1,%ebp
lea    0xddc(%rip),%rdi
mov    $0x5,%esi
mov    %eax,%r8d
xor    %eax,%eax
call   1030 <prnlog@plt>
mov    0x18(%rbx),%edi
call   1040 <des_getParityBitFromKey@plt>
mov    0x18(%rbx),%edx
mov    %edx,%ecx
and    $0x1,%ecx
cmp    %ecx,%eax
je     1260 <des_checkParity+0x140>
add    $0x1,%ebp
lea    0xdaf(%rip),%rdi
mov    $0x6,%esi
mov    %eax,%r8d
xor    %eax,%eax
call   1030 <prnlog@plt>
mov    0x1c(%rbx),%edi
call   1040 <des_getParityBitFromKey@plt>
mov    0x1c(%rbx),%edx
mov    %edx,%ecx
and    $0x1,%ecx
cmp    %ecx,%eax
jne    128c <des_checkParity+0x16c>
test   %ebp,%ebp
jne    12a5 <des_checkParity+0x185>
lea    0xdcc(%rip),%rdi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <prnlog@plt>
add    $0x1,%ebp
lea    0xd6a(%rip),%rdi
mov    $0x7,%esi
mov    %eax,%r8d
xor    %eax,%eax
call   1030 <prnlog@plt>
lea    0xd8a(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <prnlog@plt>

LLVM IR (-O0):
@.str = [54 x i8] c"[+] parity1 fail, byte %d [%02x] was %d, should be %d\00"
@.str.1 = [21 x i8] c"[+] parity fails: %d\00"
@.str.2 = [52 x i8] c"[+] Key syntax is with parity bits inside each byte\00"
define void @des_checkParity(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %2
store i32 0, i32* %4
store i32 0, i32* %3
br label %6
6: ; preds = %42, %1
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 8
br i1 %8, label %9, label %45
9: ; preds = %6
%10 = load i32*, i32** %2
%11 = load i32, i32* %3
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i32, i32* %10, i64 %12
%14 = load i32, i32* %13
%15 = call i32 @des_getParityBitFromKey(i32 %14)
store i32 %15, i32* %5
%16 = load i32, i32* %5
%17 = load i32*, i32** %2
%18 = load i32, i32* %3
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i32, i32* %17, i64 %19
%21 = load i32, i32* %20
%22 = and i32 %21, 1
%23 = icmp ne i32 %16, %22
br i1 %23, label %24, label %41
24: ; preds = %9
%25 = load i32, i32* %4
%26 = add nsw i32 %25, 1
store i32 %26, i32* %4
%27 = load i32, i32* %3
%28 = load i32*, i32** %2
%29 = load i32, i32* %3
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %28, i64 %30
%32 = load i32, i32* %31
%33 = load i32*, i32** %2
%34 = load i32, i32* %3
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %33, i64 %35
%37 = load i32, i32* %36
%38 = and i32 %37, 1
%39 = load i32, i32* %5
%40 = call i32 (i8*, ...) @prnlog(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i32 %27, i32 %32, i32 %38, i32 %39)
br label %41
41: ; preds = %24, %9
br label %42
42: ; preds = %41
%43 = load i32, i32* %3
%44 = add nsw i32 %43, 1
store i32 %44, i32* %3
br label %6
45: ; preds = %6
%46 = load i32, i32* %4
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %51
48: ; preds = %45
%49 = load i32, i32* %4
%50 = call i32 (i8*, ...) @prnlog(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %49)
br label %53
51: ; preds = %45
%52 = call i32 (i8*, ...) @prnlog(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0))
br label %53
53: ; preds = %51, %48
ret void
}

LLVM IR (-O2):
@.str = [54 x i8] c"[+] parity1 fail, byte %d [%02x] was %d, should be %d\00"
@.str.1 = [21 x i8] c"[+] parity fails: %d\00"
@.str.2 = [52 x i8] c"[+] Key syntax is with parity bits inside each byte\00"
define void @des_checkParity(i32* nocapture %0) {
%2 = load i32, i32* %0
%3 = tail call i32 @des_getParityBitFromKey(i32 %2)
%4 = load i32, i32* %0
%5 = and i32 %4, 1
%6 = icmp eq i32 %3, %5
br i1 %6, label %9, label %7
7: ; preds = %1
%8 = tail call i32 (i8*, ...) @prnlog(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i32 0, i32 %4, i32 %5, i32 %3)
br label %9
9: ; preds = %7, %1
%10 = phi i32 [ 1, %7 ], [ 0, %1 ]
%11 = getelementptr inbounds i32, i32* %0, i64 1
%12 = load i32, i32* %11
%13 = tail call i32 @des_getParityBitFromKey(i32 %12)
%14 = load i32, i32* %11
%15 = and i32 %14, 1
%16 = icmp eq i32 %13, %15
br i1 %16, label %20, label %17
17: ; preds = %9
%18 = add nuw nsw i32 %10, 1
%19 = tail call i32 (i8*, ...) @prnlog(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i32 1, i32 %14, i32 %15, i32 %13)
br label %20
20: ; preds = %17, %9
%21 = phi i32 [ %18, %17 ], [ %10, %9 ]
%22 = getelementptr inbounds i32, i32* %0, i64 2
%23 = load i32, i32* %22
%24 = tail call i32 @des_getParityBitFromKey(i32 %23)
%25 = load i32, i32* %22
%26 = and i32 %25, 1
%27 = icmp eq i32 %24, %26
br i1 %27, label %31, label %28
28: ; preds = %20
%29 = add nuw nsw i32 %21, 1
%30 = tail call i32 (i8*, ...) @prnlog(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i32 2, i32 %25, i32 %26, i32 %24)
br label %31
31: ; preds = %28, %20
%32 = phi i32 [ %29, %28 ], [ %21, %20 ]
%33 = getelementptr inbounds i32, i32* %0, i64 3
%34 = load i32, i32* %33
%35 = tail call i32 @des_getParityBitFromKey(i32 %34)
%36 = load i32, i32* %33
%37 = and i32 %36, 1
%38 = icmp eq i32 %35, %37
br i1 %38, label %42, label %39
39: ; preds = %31
%40 = add nuw nsw i32 %32, 1
%41 = tail call i32 (i8*, ...) @prnlog(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i32 3, i32 %36, i32 %37, i32 %35)
br label %42
42: ; preds = %39, %31
%43 = phi i32 [ %40, %39 ], [ %32, %31 ]
%44 = getelementptr inbounds i32, i32* %0, i64 4
%45 = load i32, i32* %44
%46 = tail call i32 @des_getParityBitFromKey(i32 %45)
%47 = load i32, i32* %44
%48 = and i32 %47, 1
%49 = icmp eq i32 %46, %48
br i1 %49, label %53, label %50
50: ; preds = %42
%51 = add nuw nsw i32 %43, 1
%52 = tail call i32 (i8*, ...) @prnlog(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i32 4, i32 %47, i32 %48, i32 %46)
br label %53
53: ; preds = %50, %42
%54 = phi i32 [ %51, %50 ], [ %43, %42 ]
%55 = getelementptr inbounds i32, i32* %0, i64 5
%56 = load i32, i32* %55
%57 = tail call i32 @des_getParityBitFromKey(i32 %56)
%58 = load i32, i32* %55
%59 = and i32 %58, 1
%60 = icmp eq i32 %57, %59
br i1 %60, label %64, label %61
61: ; preds = %53
%62 = add nuw nsw i32 %54, 1
%63 = tail call i32 (i8*, ...) @prnlog(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i32 5, i32 %58, i32 %59, i32 %57)
br label %64
64: ; preds = %61, %53
%65 = phi i32 [ %62, %61 ], [ %54, %53 ]
%66 = getelementptr inbounds i32, i32* %0, i64 6
%67 = load i32, i32* %66
%68 = tail call i32 @des_getParityBitFromKey(i32 %67)
%69 = load i32, i32* %66
%70 = and i32 %69, 1
%71 = icmp eq i32 %68, %70
br i1 %71, label %75, label %72
72: ; preds = %64
%73 = add nuw nsw i32 %65, 1
%74 = tail call i32 (i8*, ...) @prnlog(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i32 6, i32 %69, i32 %70, i32 %68)
br label %75
75: ; preds = %72, %64
%76 = phi i32 [ %73, %72 ], [ %65, %64 ]
%77 = getelementptr inbounds i32, i32* %0, i64 7
%78 = load i32, i32* %77
%79 = tail call i32 @des_getParityBitFromKey(i32 %78)
%80 = load i32, i32* %77
%81 = and i32 %80, 1
%82 = icmp eq i32 %79, %81
br i1 %82, label %86, label %83
83: ; preds = %75
%84 = add nuw nsw i32 %76, 1
%85 = tail call i32 (i8*, ...) @prnlog(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i32 7, i32 %80, i32 %81, i32 %79)
br label %88
86: ; preds = %75
%87 = icmp eq i32 %76, 0
br i1 %87, label %91, label %88
88: ; preds = %83, %86
%89 = phi i32 [ %84, %83 ], [ %76, %86 ]
%90 = tail call i32 (i8*, ...) @prnlog(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %89)
br label %93
91: ; preds = %86
%92 = tail call i32 (i8*, ...) @prnlog(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0))
br label %93
93: ; preds = %91, %88
ret void
}