#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 sync_file_info {
  unsigned int num_fences;
  scalar_t__ sync_fence_info;
};
struct sync_fence_info {
  int status;
};

/* Variables and functions */
struct sync_file_info *sync_file_info(int);
int /*<<< orphan*/ sync_file_info_free(struct sync_file_info *);
int sync_fence_count_with_status(int fd, int status) {
  unsigned int i, count = 0;
  struct sync_fence_info *fence_info = NULL;
  struct sync_file_info *info = sync_file_info(fd);
  if (!info)
    return -1;
  fence_info = (struct sync_fence_info *)info->sync_fence_info;
  for (i = 0; i < info->num_fences; i++) {
    if (fence_info[i].status == status)
      count++;
  }
  sync_file_info_free(info);
  return count;
}


x86 assembly (clang, -O0):
<sync_fence_count_with_status>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <sync_file_info@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1160 <sync_fence_count_with_status+0x40>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c0 <sync_fence_count_with_status+0xa0>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0x28(%rbp),%rcx
cmp    (%rcx),%eax
jae    11b1 <sync_fence_count_with_status+0x91>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    (%rax,%rcx,4),%eax
cmp    -0xc(%rbp),%eax
jne    119e <sync_fence_count_with_status+0x7e>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a3 <sync_fence_count_with_status+0x83>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1173 <sync_fence_count_with_status+0x53>
mov    -0x28(%rbp),%rdi
call   1030 <sync_file_info_free@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sync_fence_count_with_status>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
call   1040 <sync_file_info@plt>
test   %rax,%rax
je     1148 <sync_fence_count_with_status+0x28>
mov    (%rax),%ecx
test   %rcx,%rcx
je     1152 <sync_fence_count_with_status+0x32>
mov    0x8(%rax),%rdx
cmp    $0x8,%ecx
jae    1159 <sync_fence_count_with_status+0x39>
xor    %esi,%esi
xor    %ebp,%ebp
jmp    1220 <sync_fence_count_with_status+0x100>
mov    $0xffffffff,%ebp
jmp    123c <sync_fence_count_with_status+0x11c>
xor    %ebp,%ebp
jmp    1234 <sync_fence_count_with_status+0x114>
mov    %ecx,%esi
and    $0xfffffff8,%esi
movd   %ebx,%xmm0
pshufd $0x0,%xmm0,%xmm0
lea    -0x8(%rsi),%rdi
mov    %rdi,%r8
shr    $0x3,%r8
add    $0x1,%r8
test   %rdi,%rdi
je     1245 <sync_fence_count_with_status+0x125>
mov    %r8,%rdi
and    $0xfffffffffffffffe,%rdi
pxor   %xmm1,%xmm1
xor    %ebp,%ebp
pxor   %xmm2,%xmm2
movdqu (%rdx,%rbp,4),%xmm3
movdqu 0x10(%rdx,%rbp,4),%xmm4
movdqu 0x20(%rdx,%rbp,4),%xmm5
movdqu 0x30(%rdx,%rbp,4),%xmm6
pcmpeqd %xmm0,%xmm3
psubd  %xmm3,%xmm1
pcmpeqd %xmm0,%xmm4
psubd  %xmm4,%xmm2
pcmpeqd %xmm0,%xmm5
psubd  %xmm5,%xmm1
pcmpeqd %xmm0,%xmm6
psubd  %xmm6,%xmm2
add    $0x10,%rbp
add    $0xfffffffffffffffe,%rdi
jne    1190 <sync_fence_count_with_status+0x70>
test   $0x1,%r8b
je     11f2 <sync_fence_count_with_status+0xd2>
movdqu (%rdx,%rbp,4),%xmm3
movdqu 0x10(%rdx,%rbp,4),%xmm4
pcmpeqd %xmm0,%xmm3
psubd  %xmm3,%xmm1
pcmpeqd %xmm0,%xmm4
psubd  %xmm4,%xmm2
paddd  %xmm2,%xmm1
pshufd $0xee,%xmm1,%xmm0
paddd  %xmm1,%xmm0
pshufd $0x55,%xmm0,%xmm1
paddd  %xmm0,%xmm1
movd   %xmm1,%ebp
cmp    %rcx,%rsi
je     1234 <sync_fence_count_with_status+0x114>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %edi,%edi
cmp    %ebx,(%rdx,%rsi,4)
sete   %dil
add    %edi,%ebp
add    $0x1,%rsi
cmp    %rsi,%rcx
jne    1220 <sync_fence_count_with_status+0x100>
mov    %rax,%rdi
call   1030 <sync_file_info_free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
pxor   %xmm1,%xmm1
xor    %ebp,%ebp
pxor   %xmm2,%xmm2
test   $0x1,%r8b
jne    11d7 <sync_fence_count_with_status+0xb7>
jmp    11f2 <sync_fence_count_with_status+0xd2>

LLVM IR (-O0):
%struct.sync_fence_info = type { i32 }
%struct.sync_file_info = type { i32, i64 }
define i32 @sync_fence_count_with_status(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.sync_fence_info*
%9 = alloca %struct.sync_file_info*
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 0, i32* %7
store %struct.sync_fence_info* null, %struct.sync_fence_info** %8
%10 = load i32, i32* %4
%11 = call %struct.sync_file_info* @sync_file_info(i32 %10)
store %struct.sync_file_info* %11, %struct.sync_file_info** %9
%12 = load %struct.sync_file_info*, %struct.sync_file_info** %9
%13 = icmp ne %struct.sync_file_info* %12, null
br i1 %13, label %15, label %14
14: ; preds = %2
store i32 -1, i32* %3
br label %46
15: ; preds = %2
%16 = load %struct.sync_file_info*, %struct.sync_file_info** %9
%17 = getelementptr inbounds %struct.sync_file_info, %struct.sync_file_info* %16, i32 0, i32 1
%18 = load i64, i64* %17
%19 = inttoptr i64 %18 to %struct.sync_fence_info*
store %struct.sync_fence_info* %19, %struct.sync_fence_info** %8
store i32 0, i32* %6
br label %20
20: ; preds = %39, %15
%21 = load i32, i32* %6
%22 = load %struct.sync_file_info*, %struct.sync_file_info** %9
%23 = getelementptr inbounds %struct.sync_file_info, %struct.sync_file_info* %22, i32 0, i32 0
%24 = load i32, i32* %23
%25 = icmp ult i32 %21, %24
br i1 %25, label %26, label %42
26: ; preds = %20
%27 = load %struct.sync_fence_info*, %struct.sync_fence_info** %8
%28 = load i32, i32* %6
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds %struct.sync_fence_info, %struct.sync_fence_info* %27, i64 %29
%31 = getelementptr inbounds %struct.sync_fence_info, %struct.sync_fence_info* %30, i32 0, i32 0
%32 = load i32, i32* %31
%33 = load i32, i32* %5
%34 = icmp eq i32 %32, %33
br i1 %34, label %35, label %38
35: ; preds = %26
%36 = load i32, i32* %7
%37 = add i32 %36, 1
store i32 %37, i32* %7
br label %38
38: ; preds = %35, %26
br label %39
39: ; preds = %38
%40 = load i32, i32* %6
%41 = add i32 %40, 1
store i32 %41, i32* %6
br label %20
42: ; preds = %20
%43 = load %struct.sync_file_info*, %struct.sync_file_info** %9
%44 = call i32 @sync_file_info_free(%struct.sync_file_info* %43)
%45 = load i32, i32* %7
store i32 %45, i32* %3
br label %46
46: ; preds = %42, %14
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
%struct.sync_fence_info = type { i32 }
%struct.sync_file_info = type { i32, i64 }
define i32 @sync_fence_count_with_status(i32 %0, i32 %1) {
%3 = tail call %struct.sync_file_info* @sync_file_info(i32 %0)
%4 = icmp eq %struct.sync_file_info* %3, null
br i1 %4, label %103, label %5
5: ; preds = %2
%6 = getelementptr inbounds %struct.sync_file_info, %struct.sync_file_info* %3, i64 0, i32 1
%7 = load i64, i64* %6
%8 = inttoptr i64 %7 to %struct.sync_fence_info*
%9 = getelementptr inbounds %struct.sync_file_info, %struct.sync_file_info* %3, i64 0, i32 0
%10 = load i32, i32* %9
%11 = icmp eq i32 %10, 0
br i1 %11, label %100, label %12
12: ; preds = %5
%13 = zext i32 %10 to i64
%14 = icmp ult i32 %10, 8
br i1 %14, label %87, label %15
15: ; preds = %12
%16 = and i64 %13, 4294967288
%17 = insertelement <4 x i32> poison, i32 %1, i64 0
%18 = shufflevector <4 x i32> %17, <4 x i32> poison, <4 x i32> zeroinitializer
%19 = insertelement <4 x i32> poison, i32 %1, i64 0
%20 = shufflevector <4 x i32> %19, <4 x i32> poison, <4 x i32> zeroinitializer
%21 = add nsw i64 %16, -8
%22 = lshr exact i64 %21, 3
%23 = add nuw nsw i64 %22, 1
%24 = and i64 %23, 1
%25 = icmp eq i64 %21, 0
br i1 %25, label %61, label %26
26: ; preds = %15
%27 = and i64 %23, 4611686018427387902
br label %28
28: ; preds = %28, %26
%29 = phi i64 [ 0, %26 ], [ %58, %28 ]
%30 = phi <4 x i32> [ zeroinitializer, %26 ], [ %56, %28 ]
%31 = phi <4 x i32> [ zeroinitializer, %26 ], [ %57, %28 ]
%32 = phi i64 [ 0, %26 ], [ %59, %28 ]
%33 = getelementptr inbounds %struct.sync_fence_info, %struct.sync_fence_info* %8, i64 %29, i32 0
%34 = bitcast i32* %33 to <4 x i32>*
%35 = load <4 x i32>, <4 x i32>* %34
%36 = getelementptr inbounds i32, i32* %33, i64 4
%37 = bitcast i32* %36 to <4 x i32>*
%38 = load <4 x i32>, <4 x i32>* %37
%39 = icmp eq <4 x i32> %35, %18
%40 = icmp eq <4 x i32> %38, %20
%41 = zext <4 x i1> %39 to <4 x i32>
%42 = zext <4 x i1> %40 to <4 x i32>
%43 = add <4 x i32> %30, %41
%44 = add <4 x i32> %31, %42
%45 = or i64 %29, 8
%46 = getelementptr inbounds %struct.sync_fence_info, %struct.sync_fence_info* %8, i64 %45, i32 0
%47 = bitcast i32* %46 to <4 x i32>*
%48 = load <4 x i32>, <4 x i32>* %47
%49 = getelementptr inbounds i32, i32* %46, i64 4
%50 = bitcast i32* %49 to <4 x i32>*
%51 = load <4 x i32>, <4 x i32>* %50
%52 = icmp eq <4 x i32> %48, %18
%53 = icmp eq <4 x i32> %51, %20
%54 = zext <4 x i1> %52 to <4 x i32>
%55 = zext <4 x i1> %53 to <4 x i32>
%56 = add <4 x i32> %43, %54
%57 = add <4 x i32> %44, %55
%58 = add nuw i64 %29, 16
%59 = add i64 %32, 2
%60 = icmp eq i64 %59, %27
br i1 %60, label %61, label %28
61: ; preds = %28, %15
%62 = phi <4 x i32> [ undef, %15 ], [ %56, %28 ]
%63 = phi <4 x i32> [ undef, %15 ], [ %57, %28 ]
%64 = phi i64 [ 0, %15 ], [ %58, %28 ]
%65 = phi <4 x i32> [ zeroinitializer, %15 ], [ %56, %28 ]
%66 = phi <4 x i32> [ zeroinitializer, %15 ], [ %57, %28 ]
%67 = icmp eq i64 %24, 0
br i1 %67, label %81, label %68
68: ; preds = %61
%69 = getelementptr inbounds %struct.sync_fence_info, %struct.sync_fence_info* %8, i64 %64, i32 0
%70 = bitcast i32* %69 to <4 x i32>*
%71 = load <4 x i32>, <4 x i32>* %70
%72 = getelementptr inbounds i32, i32* %69, i64 4
%73 = bitcast i32* %72 to <4 x i32>*
%74 = load <4 x i32>, <4 x i32>* %73
%75 = icmp eq <4 x i32> %71, %18
%76 = icmp eq <4 x i32> %74, %20
%77 = zext <4 x i1> %75 to <4 x i32>
%78 = zext <4 x i1> %76 to <4 x i32>
%79 = add <4 x i32> %65, %77
%80 = add <4 x i32> %66, %78
br label %81
81: ; preds = %61, %68
%82 = phi <4 x i32> [ %62, %61 ], [ %79, %68 ]
%83 = phi <4 x i32> [ %63, %61 ], [ %80, %68 ]
%84 = add <4 x i32> %83, %82
%85 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %84)
%86 = icmp eq i64 %16, %13
br i1 %86, label %100, label %87
87: ; preds = %12, %81
%88 = phi i64 [ 0, %12 ], [ %16, %81 ]
%89 = phi i32 [ 0, %12 ], [ %85, %81 ]
br label %90
90: ; preds = %87, %90
%91 = phi i64 [ %98, %90 ], [ %88, %87 ]
%92 = phi i32 [ %97, %90 ], [ %89, %87 ]
%93 = getelementptr inbounds %struct.sync_fence_info, %struct.sync_fence_info* %8, i64 %91, i32 0
%94 = load i32, i32* %93
%95 = icmp eq i32 %94, %1
%96 = zext i1 %95 to i32
%97 = add i32 %92, %96
%98 = add nuw nsw i64 %91, 1
%99 = icmp eq i64 %98, %13
br i1 %99, label %100, label %90
100: ; preds = %90, %81, %5
%101 = phi i32 [ 0, %5 ], [ %85, %81 ], [ %97, %90 ]
%102 = tail call i32 @sync_file_info_free(%struct.sync_file_info* %3)
br label %103
103: ; preds = %2, %100
%104 = phi i32 [ %101, %100 ], [ -1, %2 ]
ret i32 %104
}