#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 count_char_bits(char);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, int);
int peerContainsUndownloadedPieces(char *peer_buffer, char *own_buffer,
                                   int bit_pieces) {
  int x;
  int count = 0;
  for (x = 0; x < bit_pieces; x++) {
    char *tester = malloc(1);
    char common_bits = *(peer_buffer + x) & *(own_buffer + x);
    if ((*(peer_buffer + x) - common_bits) != 0)
      return 1;
    printf("count bits%d\n", count_char_bits(*tester));
    free(tester);
  }
  return 0;
}


x86 assembly (clang, -O0):
<peerContainsUndownloadedPieces>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11f0 <peerContainsUndownloadedPieces+0xb0>
mov    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    -0x18(%rbp),%rcx
movslq -0x20(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
and    %ecx,%eax
mov    %al,-0x31(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
movsbl -0x31(%rbp),%ecx
sub    %ecx,%eax
cmp    $0x0,%eax
je     11bf <peerContainsUndownloadedPieces+0x7f>
movl   $0x1,-0x4(%rbp)
jmp    11f7 <peerContainsUndownloadedPieces+0xb7>
mov    -0x30(%rbp),%rax
movsbl (%rax),%edi
call   1040 <count_char_bits@plt>
mov    %eax,%esi
lea    0xe2c(%rip),%rdi
call   1050 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1161 <peerContainsUndownloadedPieces+0x21>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<peerContainsUndownloadedPieces>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
jle    11a9 <peerContainsUndownloadedPieces+0x69>
mov    %rsi,%r14
mov    %rdi,%r12
mov    %edx,%r13d
xor    %r15d,%r15d
nopl   0x0(%rax,%rax,1)
mov    $0x1,%ebp
mov    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
movzbl (%r14,%r15,1),%eax
not    %al
test   %al,(%r12,%r15,1)
jne    11ab <peerContainsUndownloadedPieces+0x6b>
xor    %ebp,%ebp
xor    %edi,%edi
call   1040 <count_char_bits@plt>
lea    0xe71(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
add    $0x1,%r15
cmp    %r15,%r13
jne    1160 <peerContainsUndownloadedPieces+0x20>
jmp    11ab <peerContainsUndownloadedPieces+0x6b>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"count bits%d\0A\00"
define i32 @peerContainsUndownloadedPieces(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 0, i32* %9
store i32 0, i32* %8
br label %12
12: ; preds = %50, %3
%13 = load i32, i32* %8
%14 = load i32, i32* %7
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %53
16: ; preds = %12
%17 = call i8* @malloc(i32 1)
store i8* %17, i8** %10
%18 = load i8*, i8** %5
%19 = load i32, i32* %8
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = load i8*, i8** %6
%25 = load i32, i32* %8
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = and i32 %23, %29
%31 = trunc i32 %30 to i8
store i8 %31, i8* %11
%32 = load i8*, i8** %5
%33 = load i32, i32* %8
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = load i8, i8* %11
%39 = sext i8 %38 to i32
%40 = sub nsw i32 %37, %39
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %43
42: ; preds = %16
store i32 1, i32* %4
br label %54
43: ; preds = %16
%44 = load i8*, i8** %10
%45 = load i8, i8* %44
%46 = call i32 @count_char_bits(i8 signext %45)
%47 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %46)
%48 = load i8*, i8** %10
%49 = call i32 @free(i8* %48)
br label %50
50: ; preds = %43
%51 = load i32, i32* %8
%52 = add nsw i32 %51, 1
store i32 %52, i32* %8
br label %12
53: ; preds = %12
store i32 0, i32* %4
br label %54
54: ; preds = %53, %42
%55 = load i32, i32* %4
ret i32 %55
}

LLVM IR (-O2):
@.str = [14 x i8] c"count bits%d\0A\00"
define i32 @peerContainsUndownloadedPieces(i8* nocapture %0, i8* nocapture %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %22
5: ; preds = %3
%6 = zext i32 %2 to i64
br label %7
7: ; preds = %5, %16
%8 = phi i64 [ 0, %5 ], [ %20, %16 ]
%9 = tail call dereferenceable_or_null(1) i8* @malloc(i32 1)
%10 = getelementptr inbounds i8, i8* %0, i64 %8
%11 = load i8, i8* %10
%12 = getelementptr inbounds i8, i8* %1, i64 %8
%13 = load i8, i8* %12
%14 = and i8 %13, %11
%15 = icmp eq i8 %11, %14
br i1 %15, label %16, label %22
16: ; preds = %7
%17 = tail call i32 @count_char_bits(i8 signext undef)
%18 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = tail call i32 @free(i8* %9)
%20 = add nuw nsw i64 %8, 1
%21 = icmp eq i64 %20, %6
br i1 %21, label %22, label %7
22: ; preds = %16, %7, %3
%23 = phi i32 [ 0, %3 ], [ 1, %7 ], [ 0, %16 ]
ret i32 %23
}