#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 /*<<< 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*/ *);
unsigned long long int
udev_queue_get_udev_seqnum(struct udev_queue *udev_queue) {
  unsigned long long int seqnum_udev;
  FILE *queue_file;
  queue_file = open_queue_file(udev_queue, &seqnum_udev);
  if (queue_file == NULL)
    return 0;
  for (;;) {
    unsigned long long int seqnum;
    ssize_t devpath_len;
    if (udev_queue_read_seqnum(queue_file, &seqnum) < 0)
      break;
    devpath_len = udev_queue_skip_devpath(queue_file);
    if (devpath_len < 0)
      break;
    if (devpath_len > 0)
      seqnum_udev = seqnum;
  }
  fclose(queue_file);
  return seqnum_udev;
}


x86 assembly (clang, -O0):
<udev_queue_get_udev_seqnum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1060 <open_queue_file@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1175 <udev_queue_get_udev_seqnum+0x35>
movq   $0x0,-0x8(%rbp)
jmp    11dc <udev_queue_get_udev_seqnum+0x9c>
jmp    117a <udev_queue_get_udev_seqnum+0x3a>
mov    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1030 <udev_queue_read_seqnum@plt>
cmp    $0x0,%rax
jge    1196 <udev_queue_get_udev_seqnum+0x56>
jmp    11cb <udev_queue_get_udev_seqnum+0x8b>
mov    -0x20(%rbp),%rdi
call   1050 <udev_queue_skip_devpath@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jge    11b3 <udev_queue_get_udev_seqnum+0x73>
jmp    11cb <udev_queue_get_udev_seqnum+0x8b>
cmpq   $0x0,-0x30(%rbp)
jle    11c6 <udev_queue_get_udev_seqnum+0x86>
mov    -0x28(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    117a <udev_queue_get_udev_seqnum+0x3a>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<udev_queue_get_udev_seqnum>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0x10(%rsp),%rsi
call   1060 <open_queue_file@plt>
test   %rax,%rax
je     11ba <udev_queue_get_udev_seqnum+0x7a>
mov    %rax,%rbx
lea    0x8(%rsp),%rsi
mov    %rax,%rdi
call   1030 <udev_queue_read_seqnum@plt>
test   %rax,%rax
js     11ab <udev_queue_get_udev_seqnum+0x6b>
lea    0x8(%rsp),%r14
jmp    1190 <udev_queue_get_udev_seqnum+0x50>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <udev_queue_read_seqnum@plt>
test   %rax,%rax
js     11ab <udev_queue_get_udev_seqnum+0x6b>
mov    %rbx,%rdi
call   1050 <udev_queue_skip_devpath@plt>
test   %rax,%rax
js     11ab <udev_queue_get_udev_seqnum+0x6b>
je     1180 <udev_queue_get_udev_seqnum+0x40>
mov    0x8(%rsp),%rax
mov    %rax,0x10(%rsp)
jmp    1180 <udev_queue_get_udev_seqnum+0x40>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0x10(%rsp),%rax
jmp    11bc <udev_queue_get_udev_seqnum+0x7c>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.udev_queue = type { i32 }
define i64 @udev_queue_get_udev_seqnum(%struct.udev_queue* %0) {
%2 = alloca i64
%3 = alloca %struct.udev_queue*
%4 = alloca i64
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i64
store %struct.udev_queue* %0, %struct.udev_queue** %3
%8 = load %struct.udev_queue*, %struct.udev_queue** %3
%9 = call i32* @open_queue_file(%struct.udev_queue* %8, i64* %4)
store i32* %9, i32** %5
%10 = load i32*, i32** %5
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %13
12: ; preds = %1
store i64 0, i64* %2
br label %35
13: ; preds = %1
br label %14
14: ; preds = %30, %13
%15 = load i32*, i32** %5
%16 = call i64 @udev_queue_read_seqnum(i32* %15, i64* %6)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %14
br label %31
19: ; preds = %14
%20 = load i32*, i32** %5
%21 = call i64 @udev_queue_skip_devpath(i32* %20)
store i64 %21, i64* %7
%22 = load i64, i64* %7
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %19
br label %31
25: ; preds = %19
%26 = load i64, i64* %7
%27 = icmp sgt i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = load i64, i64* %6
store i64 %29, i64* %4
br label %30
30: ; preds = %28, %25
br label %14
31: ; preds = %24, %18
%32 = load i32*, i32** %5
%33 = call i32 @fclose(i32* %32)
%34 = load i64, i64* %4
store i64 %34, i64* %2
br label %35
35: ; preds = %31, %12
%36 = load i64, i64* %2
ret i64 %36
}

LLVM IR (-O2):
%struct.udev_queue = type { i32 }
define i64 @udev_queue_get_udev_seqnum(%struct.udev_queue* %0) {
%2 = alloca i64
%3 = alloca i64
%4 = bitcast i64* %2 to i8*
%5 = call i32* @open_queue_file(%struct.udev_queue* %0, i64* %2)
%6 = icmp eq i32* %5, null
br i1 %6, label %24, label %7
7: ; preds = %1
%8 = bitcast i64* %3 to i8*
%9 = call i64 @udev_queue_read_seqnum(i32* %5, i64* %3)
%10 = icmp slt i64 %9, 0
br i1 %10, label %21, label %11
11: ; preds = %7, %18
%12 = call i64 @udev_queue_skip_devpath(i32* %5)
%13 = icmp slt i64 %12, 0
br i1 %13, label %21, label %14
14: ; preds = %11
%15 = icmp eq i64 %12, 0
br i1 %15, label %18, label %16
16: ; preds = %14
%17 = load i64, i64* %3
store i64 %17, i64* %2
br label %18
18: ; preds = %14, %16
%19 = call i64 @udev_queue_read_seqnum(i32* %5, i64* %3)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %11
21: ; preds = %11, %18, %7
%22 = call i32 @fclose(i32* %5)
%23 = load i64, i64* %2
br label %24
24: ; preds = %1, %21
%25 = phi i64 [ %23, %21 ], [ 0, %1 ]
ret i64 %25
}