#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 udev_queue {
  int dummy;
};
typedef scalar_t__ ssize_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EINVAL;
int EOVERFLOW;
int INT_MAX;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *open_queue_file(struct udev_queue *, unsigned long long *);
scalar_t__ udev_queue_read_seqnum(int /*<<< orphan*/ *, unsigned long long *);
scalar_t__ udev_queue_skip_devpath(int /*<<< orphan*/ *);
__attribute__((visibility("default"))) int
udev_queue_get_seqnum_sequence_is_finished(struct udev_queue *udev_queue,
                                           unsigned long long int start,
                                           unsigned long long int end) {
  unsigned long long int seqnum;
  ssize_t devpath_len;
  int unfinished;
  FILE *queue_file;
  if (udev_queue == NULL)
    return -EINVAL;
  queue_file = open_queue_file(udev_queue, &seqnum);
  if (queue_file == NULL)
    return 1;
  if (start < seqnum)
    start = seqnum;
  if (start > end) {
    fclose(queue_file);
    return 1;
  }
  if (end - start > INT_MAX - 1) {
    fclose(queue_file);
    return -EOVERFLOW;
  }
  unfinished = end - start;
  do {
    if (udev_queue_read_seqnum(queue_file, &seqnum) < 0)
      break;
    devpath_len = udev_queue_skip_devpath(queue_file);
    if (devpath_len < 0)
      break;
    if (start == seqnum && devpath_len > 0)
      unfinished++;
    if (devpath_len == 0) {
      if (seqnum >= start && seqnum <= end)
        unfinished--;
    }
  } while (unfinished > 0);
  fclose(queue_file);
  return (unfinished == 0);
}


x86 assembly (clang, -O0):
<udev_queue_get_seqnum_sequence_is_finished>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1172 <udev_queue_get_seqnum_sequence_is_finished+0x32>
xor    %eax,%eax
mov    0x2e68(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    12d1 <udev_queue_get_seqnum_sequence_is_finished+0x191>
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1060 <open_queue_file@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    119a <udev_queue_get_seqnum_sequence_is_finished+0x5a>
movl   $0x1,-0x4(%rbp)
jmp    12d1 <udev_queue_get_seqnum_sequence_is_finished+0x191>
mov    -0x18(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    11b0 <udev_queue_get_seqnum_sequence_is_finished+0x70>
mov    -0x28(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jbe    11d3 <udev_queue_get_seqnum_sequence_is_finished+0x93>
mov    -0x40(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    12d1 <udev_queue_get_seqnum_sequence_is_finished+0x191>
mov    -0x20(%rbp),%rax
sub    -0x18(%rbp),%rax
mov    0x2dfe(%rip),%rcx
mov    (%rcx),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
cmp    %rcx,%rax
jbe    120f <udev_queue_get_seqnum_sequence_is_finished+0xcf>
mov    -0x40(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
mov    0x2deb(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    12d1 <udev_queue_get_seqnum_sequence_is_finished+0x191>
mov    -0x20(%rbp),%rax
sub    -0x18(%rbp),%rax
mov    %eax,-0x34(%rbp)
mov    -0x40(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1030 <udev_queue_read_seqnum@plt>
cmp    $0x0,%rax
jge    1236 <udev_queue_get_seqnum_sequence_is_finished+0xf6>
jmp    12b9 <udev_queue_get_seqnum_sequence_is_finished+0x179>
mov    -0x40(%rbp),%rdi
call   1050 <udev_queue_skip_devpath@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jge    1253 <udev_queue_get_seqnum_sequence_is_finished+0x113>
jmp    12b9 <udev_queue_get_seqnum_sequence_is_finished+0x179>
mov    -0x18(%rbp),%rax
cmp    -0x28(%rbp),%rax
jne    1275 <udev_queue_get_seqnum_sequence_is_finished+0x135>
cmpq   $0x0,-0x30(%rbp)
jle    1275 <udev_queue_get_seqnum_sequence_is_finished+0x135>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    12aa <udev_queue_get_seqnum_sequence_is_finished+0x16a>
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jb     12a5 <udev_queue_get_seqnum_sequence_is_finished+0x165>
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
ja     12a5 <udev_queue_get_seqnum_sequence_is_finished+0x165>
mov    -0x34(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x34(%rbp)
jmp    12aa <udev_queue_get_seqnum_sequence_is_finished+0x16a>
jmp    12af <udev_queue_get_seqnum_sequence_is_finished+0x16f>
cmpl   $0x0,-0x34(%rbp)
jg     121a <udev_queue_get_seqnum_sequence_is_finished+0xda>
mov    -0x40(%rbp),%rdi
call   1040 <fclose@plt>
cmpl   $0x0,-0x34(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<udev_queue_get_seqnum_sequence_is_finished>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     1185 <udev_queue_get_seqnum_sequence_is_finished+0x45>
mov    %rdx,%r12
mov    %rsi,%r13
mov    %rsp,%rsi
call   1060 <open_queue_file@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     11ba <udev_queue_get_seqnum_sequence_is_finished+0x7a>
mov    %rax,%r15
mov    (%rsp),%rax
cmp    %r13,%rax
cmova  %rax,%r13
cmp    %r12,%r13
jbe    118e <udev_queue_get_seqnum_sequence_is_finished+0x4e>
mov    %r15,%rdi
call   1040 <fclose@plt>
jmp    11ba <udev_queue_get_seqnum_sequence_is_finished+0x7a>
mov    0x2e44(%rip),%rax
jmp    11b6 <udev_queue_get_seqnum_sequence_is_finished+0x76>
mov    %r12,%r14
sub    %r13,%r14
mov    0x2e45(%rip),%rax
movslq (%rax),%rax
add    $0xffffffffffffffff,%rax
cmp    %rax,%r14
jbe    11cb <udev_queue_get_seqnum_sequence_is_finished+0x8b>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    0x2e3a(%rip),%rax
xor    %ebp,%ebp
sub    (%rax),%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rsp,%rbp
jmp    11d5 <udev_queue_get_seqnum_sequence_is_finished+0x95>
test   %r14d,%r14d
jle    1225 <udev_queue_get_seqnum_sequence_is_finished+0xe5>
mov    %r15,%rdi
mov    %rbp,%rsi
call   1030 <udev_queue_read_seqnum@plt>
test   %rax,%rax
js     1225 <udev_queue_get_seqnum_sequence_is_finished+0xe5>
mov    %r15,%rdi
call   1050 <udev_queue_skip_devpath@plt>
test   %rax,%rax
js     1225 <udev_queue_get_seqnum_sequence_is_finished+0xe5>
mov    (%rsp),%rcx
cmp    %rcx,%r13
sete   %dl
test   %rax,%rax
setne  %bl
and    %dl,%bl
movzbl %bl,%edx
add    %edx,%r14d
test   %rax,%rax
jne    11d0 <udev_queue_get_seqnum_sequence_is_finished+0x90>
cmp    %r13,%rcx
setae  %al
cmp    %r12,%rcx
setbe  %cl
and    %al,%cl
movzbl %cl,%eax
sub    %eax,%r14d
jmp    11d0 <udev_queue_get_seqnum_sequence_is_finished+0x90>
mov    %r15,%rdi
call   1040 <fclose@plt>
xor    %ebp,%ebp
test   %r14d,%r14d
sete   %bpl
jmp    11ba <udev_queue_get_seqnum_sequence_is_finished+0x7a>

LLVM IR (-O0):
%struct.udev_queue = type { i32 }
@EINVAL = global i32 0
@INT_MAX = global i32 0
@EOVERFLOW = global i32 0
define i32 @udev_queue_get_seqnum_sequence_is_finished(%struct.udev_queue* %0, i64 %1, i64 %2) {
%4 = alloca i32
%5 = alloca %struct.udev_queue*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32*
store %struct.udev_queue* %0, %struct.udev_queue** %5
store i64 %1, i64* %6
store i64 %2, i64* %7
%12 = load %struct.udev_queue*, %struct.udev_queue** %5
%13 = icmp eq %struct.udev_queue* %12, null
br i1 %13, label %14, label %17
14: ; preds = %3
%15 = load i32, i32* @EINVAL
%16 = sub nsw i32 0, %15
store i32 %16, i32* %4
br label %100
17: ; preds = %3
%18 = load %struct.udev_queue*, %struct.udev_queue** %5
%19 = call i32* @open_queue_file(%struct.udev_queue* %18, i64* %8)
store i32* %19, i32** %11
%20 = load i32*, i32** %11
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %23
22: ; preds = %17
store i32 1, i32* %4
br label %100
23: ; preds = %17
%24 = load i64, i64* %6
%25 = load i64, i64* %8
%26 = icmp ult i64 %24, %25
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = load i64, i64* %8
store i64 %28, i64* %6
br label %29
29: ; preds = %27, %23
%30 = load i64, i64* %6
%31 = load i64, i64* %7
%32 = icmp ugt i64 %30, %31
br i1 %32, label %33, label %36
33: ; preds = %29
%34 = load i32*, i32** %11
%35 = call i32 @fclose(i32* %34)
store i32 1, i32* %4
br label %100
36: ; preds = %29
%37 = load i64, i64* %7
%38 = load i64, i64* %6
%39 = sub i64 %37, %38
%40 = load i32, i32* @INT_MAX
%41 = sub nsw i32 %40, 1
%42 = sext i32 %41 to i64
%43 = icmp ugt i64 %39, %42
br i1 %43, label %44, label %49
44: ; preds = %36
%45 = load i32*, i32** %11
%46 = call i32 @fclose(i32* %45)
%47 = load i32, i32* @EOVERFLOW
%48 = sub nsw i32 0, %47
store i32 %48, i32* %4
br label %100
49: ; preds = %36
%50 = load i64, i64* %7
%51 = load i64, i64* %6
%52 = sub i64 %50, %51
%53 = trunc i64 %52 to i32
store i32 %53, i32* %10
br label %54
54: ; preds = %91, %49
%55 = load i32*, i32** %11
%56 = call i64 @udev_queue_read_seqnum(i32* %55, i64* %8)
%57 = icmp slt i64 %56, 0
br i1 %57, label %58, label %59
58: ; preds = %54
br label %94
59: ; preds = %54
%60 = load i32*, i32** %11
%61 = call i64 @udev_queue_skip_devpath(i32* %60)
store i64 %61, i64* %9
%62 = load i64, i64* %9
%63 = icmp slt i64 %62, 0
br i1 %63, label %64, label %65
64: ; preds = %59
br label %94
65: ; preds = %59
%66 = load i64, i64* %6
%67 = load i64, i64* %8
%68 = icmp eq i64 %66, %67
br i1 %68, label %69, label %75
69: ; preds = %65
%70 = load i64, i64* %9
%71 = icmp sgt i64 %70, 0
br i1 %71, label %72, label %75
72: ; preds = %69
%73 = load i32, i32* %10
%74 = add nsw i32 %73, 1
store i32 %74, i32* %10
br label %75
75: ; preds = %72, %69, %65
%76 = load i64, i64* %9
%77 = icmp eq i64 %76, 0
br i1 %77, label %78, label %90
78: ; preds = %75
%79 = load i64, i64* %8
%80 = load i64, i64* %6
%81 = icmp uge i64 %79, %80
br i1 %81, label %82, label %89
82: ; preds = %78
%83 = load i64, i64* %8
%84 = load i64, i64* %7
%85 = icmp ule i64 %83, %84
br i1 %85, label %86, label %89
86: ; preds = %82
%87 = load i32, i32* %10
%88 = add nsw i32 %87, -1
store i32 %88, i32* %10
br label %89
89: ; preds = %86, %82, %78
br label %90
90: ; preds = %89, %75
br label %91
91: ; preds = %90
%92 = load i32, i32* %10
%93 = icmp sgt i32 %92, 0
br i1 %93, label %54, label %94
94: ; preds = %91, %64, %58
%95 = load i32*, i32** %11
%96 = call i32 @fclose(i32* %95)
%97 = load i32, i32* %10
%98 = icmp eq i32 %97, 0
%99 = zext i1 %98 to i32
store i32 %99, i32* %4
br label %100
100: ; preds = %94, %44, %33, %22, %14
%101 = load i32, i32* %4
ret i32 %101
}

LLVM IR (-O2):
%struct.udev_queue = type { i32 }
@EINVAL = global i32 0
@INT_MAX = global i32 0
@EOVERFLOW = global i32 0
define i32 @udev_queue_get_seqnum_sequence_is_finished(%struct.udev_queue* %0, i64 %1, i64 %2) {
%4 = alloca i64
%5 = bitcast i64* %4 to i8*
%6 = icmp eq %struct.udev_queue* %0, null
br i1 %6, label %7, label %10
7: ; preds = %3
%8 = load i32, i32* @EINVAL
%9 = sub nsw i32 0, %8
br label %61
10: ; preds = %3
%11 = call i32* @open_queue_file(%struct.udev_queue* %0, i64* %4)
%12 = icmp eq i32* %11, null
br i1 %12, label %61, label %13
13: ; preds = %10
%14 = load i64, i64* %4
%15 = icmp ugt i64 %14, %1
%16 = select i1 %15, i64 %14, i64 %1
%17 = icmp ugt i64 %16, %2
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = call i32 @fclose(i32* %11)
br label %61
20: ; preds = %13
%21 = sub i64 %2, %16
%22 = load i32, i32* @INT_MAX
%23 = add nsw i32 %22, -1
%24 = sext i32 %23 to i64
%25 = icmp ugt i64 %21, %24
br i1 %25, label %26, label %30
26: ; preds = %20
%27 = call i32 @fclose(i32* %11)
%28 = load i32, i32* @EOVERFLOW
%29 = sub nsw i32 0, %28
br label %61
30: ; preds = %20
%31 = trunc i64 %21 to i32
br label %32
32: ; preds = %53, %30
%33 = phi i32 [ %31, %30 ], [ %54, %53 ]
%34 = call i64 @udev_queue_read_seqnum(i32* %11, i64* %4)
%35 = icmp slt i64 %34, 0
br i1 %35, label %56, label %36
36: ; preds = %32
%37 = call i64 @udev_queue_skip_devpath(i32* %11)
%38 = icmp slt i64 %37, 0
br i1 %38, label %56, label %39
39: ; preds = %36
%40 = load i64, i64* %4
%41 = icmp eq i64 %16, %40
%42 = icmp ne i64 %37, 0
%43 = select i1 %41, i1 %42, i1 false
%44 = zext i1 %43 to i32
%45 = add nsw i32 %33, %44
%46 = icmp eq i64 %37, 0
br i1 %46, label %47, label %53
47: ; preds = %39
%48 = icmp uge i64 %40, %16
%49 = icmp ule i64 %40, %2
%50 = and i1 %48, %49
%51 = sext i1 %50 to i32
%52 = add nsw i32 %45, %51
br label %53
53: ; preds = %47, %39
%54 = phi i32 [ %45, %39 ], [ %52, %47 ]
%55 = icmp sgt i32 %54, 0
br i1 %55, label %32, label %56
56: ; preds = %36, %32, %53
%57 = phi i32 [ %33, %32 ], [ %33, %36 ], [ %54, %53 ]
%58 = call i32 @fclose(i32* %11)
%59 = icmp eq i32 %57, 0
%60 = zext i1 %59 to i32
br label %61
61: ; preds = %10, %56, %26, %18, %7
%62 = phi i32 [ %9, %7 ], [ 1, %18 ], [ %29, %26 ], [ %60, %56 ], [ 1, %10 ]
ret i32 %62
}