#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 flock {
  int /*<<< orphan*/ member_0;
};

/* Variables and functions */
int /*<<< orphan*/ F_GETLK;
int /*<<< orphan*/ F_SETLKW;
int fcntl(int, int /*<<< orphan*/, struct flock *);
int /*<<< orphan*/ flock_init(struct flock *, short, int, int);
int /*<<< orphan*/ perror(char *);
int flock_range_in_steps(int fd, int is_set, short l_type, int start, int end,
                         int step) {
  int ret = 0;
  int i = 0;
  struct flock f = {
      0,
  };
  for (i = start; i + step < end; i += step) {
    flock_init(&f, l_type, i, step);
    ret = fcntl(fd, (is_set) ? F_SETLKW : F_GETLK, &f);
    if (ret) {
      perror("fcntl");
      goto out;
    }
  }
out:
  return ret;
}


x86 assembly (clang, -O0):
<flock_range_in_steps>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dx,%ax
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %ax,-0xa(%rbp)
mov    %ecx,-0x10(%rbp)
mov    %r8d,-0x14(%rbp)
mov    %r9d,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
add    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1216 <flock_range_in_steps+0xd6>
mov    -0xa(%rbp),%ax
mov    -0x20(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    -0x28(%rbp),%rdi
movswl %ax,%esi
call   1060 <flock_init@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11ca <flock_range_in_steps+0x8a>
mov    0x2e28(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
jmp    11d6 <flock_range_in_steps+0x96>
mov    0x2e0f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0x30(%rbp),%esi
lea    -0x28(%rbp),%rdx
call   1030 <fcntl@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1203 <flock_range_in_steps+0xc3>
lea    0xe07(%rip),%rdi
call   1050 <perror@plt>
jmp    121b <flock_range_in_steps+0xdb>
jmp    1208 <flock_range_in_steps+0xc8>
mov    -0x18(%rbp),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    1184 <flock_range_in_steps+0x44>
jmp    121b <flock_range_in_steps+0xdb>
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<flock_range_in_steps>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9d,%ebx
mov    %r8d,0x14(%rsp)
mov    %esi,0x10(%rsp)
mov    %edi,%r12d
movl   $0x0,0x8(%rsp)
movswl %dx,%ebp
lea    0x8(%rsp),%r13
jmp    1174 <flock_range_in_steps+0x44>
nop
mov    (%rax),%esi
mov    %r12d,%edi
mov    %r13,%rdx
call   1030 <fcntl@plt>
mov    %r15d,%ecx
test   %eax,%eax
jne    11b9 <flock_range_in_steps+0x89>
lea    (%rcx,%rbx,1),%r15d
cmp    0x14(%rsp),%r15d
jge    11a4 <flock_range_in_steps+0x74>
mov    %r13,%rdi
mov    %ebp,%esi
mov    %ecx,%edx
mov    %ebx,%ecx
call   1050 <flock_init@plt>
mov    0x2e54(%rip),%rax
cmpl   $0x0,0x10(%rsp)
jne    1160 <flock_range_in_steps+0x30>
mov    0x2e3e(%rip),%rax
jmp    1160 <flock_range_in_steps+0x30>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%r14d
lea    0xe3d(%rip),%rdi
call   1040 <perror@plt>
jmp    11a7 <flock_range_in_steps+0x77>

LLVM IR (-O0):
%struct.flock = type { i32 }
@F_SETLKW = global i32 0
@F_GETLK = global i32 0
@.str = [6 x i8] c"fcntl\00"
define i32 @flock_range_in_steps(i32 %0, i32 %1, i16 signext %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i16
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca %struct.flock
store i32 %0, i32* %7
store i32 %1, i32* %8
store i16 %2, i16* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i32 %5, i32* %12
store i32 0, i32* %13
store i32 0, i32* %14
%16 = bitcast %struct.flock* %15 to i8*
%17 = load i32, i32* %10
store i32 %17, i32* %14
br label %18
18: ; preds = %44, %6
%19 = load i32, i32* %14
%20 = load i32, i32* %12
%21 = add nsw i32 %19, %20
%22 = load i32, i32* %11
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %48
24: ; preds = %18
%25 = load i16, i16* %9
%26 = load i32, i32* %14
%27 = load i32, i32* %12
%28 = call i32 @flock_init(%struct.flock* %15, i16 signext %25, i32 %26, i32 %27)
%29 = load i32, i32* %7
%30 = load i32, i32* %8
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %24
%33 = load i32, i32* @F_SETLKW
br label %36
34: ; preds = %24
%35 = load i32, i32* @F_GETLK
br label %36
36: ; preds = %34, %32
%37 = phi i32 [ %33, %32 ], [ %35, %34 ]
%38 = call i32 @fcntl(i32 %29, i32 %37, %struct.flock* %15)
store i32 %38, i32* %13
%39 = load i32, i32* %13
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %36
%42 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %49
43: ; preds = %36
br label %44
44: ; preds = %43
%45 = load i32, i32* %12
%46 = load i32, i32* %14
%47 = add nsw i32 %46, %45
store i32 %47, i32* %14
br label %18
48: ; preds = %18
br label %49
49: ; preds = %48, %41
%50 = load i32, i32* %13
ret i32 %50
}

LLVM IR (-O2):
%struct.flock = type { i32 }
@F_SETLKW = global i32 0
@F_GETLK = global i32 0
@.str = [6 x i8] c"fcntl\00"
define i32 @flock_range_in_steps(i32 %0, i32 %1, i16 signext %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca %struct.flock
%8 = bitcast %struct.flock* %7 to i8*
%9 = getelementptr inbounds %struct.flock, %struct.flock* %7, i64 0, i32 0
store i32 0, i32* %9
%10 = icmp eq i32 %1, 0
br label %11
11: ; preds = %15, %6
%12 = phi i32 [ %3, %6 ], [ %13, %15 ]
%13 = add nsw i32 %12, %5
%14 = icmp slt i32 %13, %4
br i1 %14, label %15, label %24
15: ; preds = %11
%16 = call i32 @flock_init(%struct.flock* %7, i16 signext %2, i32 %12, i32 %5)
%17 = load i32, i32* @F_SETLKW
%18 = load i32, i32* @F_GETLK
%19 = select i1 %10, i32 %18, i32 %17
%20 = call i32 @fcntl(i32 %0, i32 %19, %struct.flock* %7)
%21 = icmp eq i32 %20, 0
br i1 %21, label %11, label %22
22: ; preds = %15
%23 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %24
24: ; preds = %11, %22
%25 = phi i32 [ %20, %22 ], [ 0, %11 ]
ret i32 %25
}