#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 /*<<< orphan*/ uint8_t;
typedef scalar_t__ uint64_t;
typedef scalar_t__ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ set_bit(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/ *, scalar_t__);
void advance_window(uint64_t seq, uint64_t T, uint8_t *window, uint32_t W) {
  uint64_t diff = seq - T;
  if (diff > W)
    diff = W;
  while (diff--)
    set_bit(0, seq--, window, W);
}


x86 assembly (clang, -O0):
<advance_window>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rax
sub    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jle    114a <advance_window+0x3a>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    114f <advance_window+0x3f>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x28(%rbp)
cmp    $0x0,%rax
je     118d <advance_window+0x7d>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x8(%rbp)
mov    %eax,%esi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
xor    %edi,%edi
call   1030 <set_bit@plt>
jmp    114f <advance_window+0x3f>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<advance_window>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r12
sub    %rsi,%r12
cmp    %rcx,%r12
cmovg  %rcx,%r12
test   %r12,%r12
je     1158 <advance_window+0x48>
mov    %rcx,%r15
mov    %rdx,%r14
mov    %rdi,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %edi,%edi
mov    %ebx,%esi
mov    %r14,%rdx
mov    %r15,%rcx
call   1030 <set_bit@plt>
add    $0xffffffff,%ebx
add    $0xffffffffffffffff,%r12
jne    1140 <advance_window+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @advance_window(i64 %0, i64 %1, i32* %2, i64 %3) {
%5 = alloca i64
%6 = alloca i64
%7 = alloca i32*
%8 = alloca i64
%9 = alloca i64
store i64 %0, i64* %5
store i64 %1, i64* %6
store i32* %2, i32** %7
store i64 %3, i64* %8
%10 = load i64, i64* %5
%11 = load i64, i64* %6
%12 = sub nsw i64 %10, %11
store i64 %12, i64* %9
%13 = load i64, i64* %9
%14 = load i64, i64* %8
%15 = icmp sgt i64 %13, %14
br i1 %15, label %16, label %18
16: ; preds = %4
%17 = load i64, i64* %8
store i64 %17, i64* %9
br label %18
18: ; preds = %16, %4
br label %19
19: ; preds = %23, %18
%20 = load i64, i64* %9
%21 = add nsw i64 %20, -1
store i64 %21, i64* %9
%22 = icmp ne i64 %20, 0
br i1 %22, label %23, label %30
23: ; preds = %19
%24 = load i64, i64* %5
%25 = add nsw i64 %24, -1
store i64 %25, i64* %5
%26 = trunc i64 %24 to i32
%27 = load i32*, i32** %7
%28 = load i64, i64* %8
%29 = call i32 @set_bit(i32 0, i32 %26, i32* %27, i64 %28)
br label %19
30: ; preds = %19
ret void
}

LLVM IR (-O2):
define void @advance_window(i64 %0, i64 %1, i32* %2, i64 %3) {
%5 = sub nsw i64 %0, %1
%6 = icmp sgt i64 %5, %3
%7 = select i1 %6, i64 %3, i64 %5
%8 = icmp eq i64 %7, 0
br i1 %8, label %17, label %9
9: ; preds = %4, %9
%10 = phi i64 [ %12, %9 ], [ %7, %4 ]
%11 = phi i64 [ %13, %9 ], [ %0, %4 ]
%12 = add nsw i64 %10, -1
%13 = add nsw i64 %11, -1
%14 = trunc i64 %11 to i32
%15 = tail call i32 @set_bit(i32 0, i32 %14, i32* %2, i64 %3)
%16 = icmp eq i64 %12, 0
br i1 %16, label %17, label %9
17: ; preds = %9, %4
ret void
}