#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, int);
int rankWrite(FILE *fp, int start, int rank, int len) {
  for (int i = 0; i < len - 1; i++) {
    fprintf(fp, "%d:%d ", start + i, rank == i + 1 ? 1 : 0);
  }
  fprintf(fp, "%d:%d ", start + len - 1, rank >= len ? 1 : 0);
  return 1;
}


x86 assembly (clang, -O0):
<rankWrite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1179 <rankWrite+0x69>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
add    -0x18(%rbp),%edx
mov    -0x10(%rbp),%esi
mov    -0x18(%rbp),%r8d
add    $0x1,%r8d
xor    %ecx,%ecx
mov    $0x1,%eax
cmp    %r8d,%esi
cmove  %eax,%ecx
lea    0xe9a(%rip),%rsi
call   1030 <fprintf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    112c <rankWrite+0x1c>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
add    -0x14(%rbp),%edx
sub    $0x1,%edx
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%r8d
xor    %ecx,%ecx
mov    $0x1,%eax
cmp    %r8d,%esi
cmovge %eax,%ecx
lea    0xe5f(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rankWrite>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,0x8(%rsp)
mov    %esi,%ebx
mov    %rdi,%r12
lea    -0x1(%rcx),%ebp
mov    %rcx,0x10(%rsp)
cmp    $0x2,%ecx
jl     1172 <rankWrite+0x62>
mov    0x8(%rsp),%rax
lea    -0x1(%rax),%r15d
xor    %eax,%eax
lea    0xeb9(%rip),%r13
nopw   0x0(%rax,%rax,1)
lea    0x1(%rax),%r14d
lea    (%rbx,%rax,1),%edx
xor    %ecx,%ecx
cmp    %eax,%r15d
sete   %cl
mov    %r12,%rdi
mov    %r13,%rsi
call   1030 <fprintf@plt>
mov    %r14d,%eax
cmp    %r14d,%ebp
jne    1150 <rankWrite+0x40>
add    %ebx,%ebp
xor    %ecx,%ecx
mov    0x8(%rsp),%rax
cmp    0x10(%rsp),%eax
setge  %cl
lea    0xe77(%rip),%rsi
mov    %r12,%rdi
mov    %ebp,%edx
call   1030 <fprintf@plt>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%d:%d \00"
define i32 @rankWrite(i32* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store i32 0, i32* %9
br label %10
10: ; preds = %27, %4
%11 = load i32, i32* %9
%12 = load i32, i32* %8
%13 = sub nsw i32 %12, 1
%14 = icmp slt i32 %11, %13
br i1 %14, label %15, label %30
15: ; preds = %10
%16 = load i32*, i32** %5
%17 = load i32, i32* %6
%18 = load i32, i32* %9
%19 = add nsw i32 %17, %18
%20 = load i32, i32* %7
%21 = load i32, i32* %9
%22 = add nsw i32 %21, 1
%23 = icmp eq i32 %20, %22
%24 = zext i1 %23 to i64
%25 = select i1 %23, i32 1, i32 0
%26 = call i32 @fprintf(i32* %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %19, i32 %25)
br label %27
27: ; preds = %15
%28 = load i32, i32* %9
%29 = add nsw i32 %28, 1
store i32 %29, i32* %9
br label %10
30: ; preds = %10
%31 = load i32*, i32** %5
%32 = load i32, i32* %6
%33 = load i32, i32* %8
%34 = add nsw i32 %32, %33
%35 = sub nsw i32 %34, 1
%36 = load i32, i32* %7
%37 = load i32, i32* %8
%38 = icmp sge i32 %36, %37
%39 = zext i1 %38 to i64
%40 = select i1 %38, i32 1, i32 0
%41 = call i32 @fprintf(i32* %31, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %35, i32 %40)
ret i32 1
}

LLVM IR (-O2):
@.str = [7 x i8] c"%d:%d \00"
define i32 @rankWrite(i32* nocapture %0, i32 %1, i32 %2, i32 %3) {
%5 = add i32 %3, -1
%6 = icmp sgt i32 %3, 1
br i1 %6, label %12, label %7
7: ; preds = %12, %4
%8 = add i32 %5, %1
%9 = icmp sge i32 %2, %3
%10 = zext i1 %9 to i32
%11 = tail call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %10)
ret i32 1
12: ; preds = %4, %12
%13 = phi i32 [ %15, %12 ], [ 0, %4 ]
%14 = add nsw i32 %13, %1
%15 = add nuw nsw i32 %13, 1
%16 = icmp eq i32 %15, %2
%17 = zext i1 %16 to i32
%18 = tail call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %14, i32 %17)
%19 = icmp eq i32 %15, %5
br i1 %19, label %7, label %12
}