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

/* Variables and functions */
int /*<<< orphan*/ add_rle(unsigned int *, int, int, int *, int const);
void Ptngc_comp_conv_to_rle(unsigned int *vals, const int nvals,
                            unsigned int *rle, int *nrle, const int min_rle) {
  int i;
  int j = 0;
  int nsim = 0;
  int v = -1;
  for (i = 0; i < nvals; i++) {
    if (!nsim) {
      v = vals[i];
      nsim = 1;
    } else {
      if (v == vals[i])
        nsim++;
      else {
        add_rle(rle, v, nsim, &j, min_rle);
        nsim = 1;
        v = vals[i];
      }
    }
  }
  if (nsim != 0)
    add_rle(rle, v, nsim, &j, min_rle);
  *nrle = j;
}


x86 assembly (clang, -O0):
<Ptngc_comp_conv_to_rle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0xffffffff,-0x34(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11dd <Ptngc_comp_conv_to_rle+0xcd>
cmpl   $0x0,-0x30(%rbp)
jne    1177 <Ptngc_comp_conv_to_rle+0x67>
mov    -0x8(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x34(%rbp)
movl   $0x1,-0x30(%rbp)
jmp    11ca <Ptngc_comp_conv_to_rle+0xba>
mov    -0x34(%rbp),%eax
mov    -0x8(%rbp),%rcx
movslq -0x28(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
jne    1199 <Ptngc_comp_conv_to_rle+0x89>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11c5 <Ptngc_comp_conv_to_rle+0xb5>
mov    -0x18(%rbp),%rdi
mov    -0x34(%rbp),%esi
mov    -0x30(%rbp),%edx
mov    -0x24(%rbp),%r8d
lea    -0x2c(%rbp),%rcx
call   1030 <add_rle@plt>
movl   $0x1,-0x30(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x34(%rbp)
jmp    11ca <Ptngc_comp_conv_to_rle+0xba>
jmp    11cf <Ptngc_comp_conv_to_rle+0xbf>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1147 <Ptngc_comp_conv_to_rle+0x37>
cmpl   $0x0,-0x30(%rbp)
je     11fe <Ptngc_comp_conv_to_rle+0xee>
mov    -0x18(%rbp),%rdi
mov    -0x34(%rbp),%esi
mov    -0x30(%rbp),%edx
mov    -0x24(%rbp),%r8d
lea    -0x2c(%rbp),%rcx
call   1030 <add_rle@plt>
mov    -0x2c(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Ptngc_comp_conv_to_rle>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%rbx
movl   $0x0,0xc(%rsp)
test   %esi,%esi
jle    11c3 <Ptngc_comp_conv_to_rle+0xb3>
mov    %r8d,%r15d
mov    %rdx,%r13
mov    %rdi,%rbp
mov    %rbx,0x10(%rsp)
mov    %esi,%ebx
xor    %r14d,%r14d
mov    $0xffffffff,%esi
lea    0xc(%rsp),%r12
xor    %edx,%edx
jmp    1170 <Ptngc_comp_conv_to_rle+0x60>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0x1,%edx
mov    %eax,%esi
add    $0x1,%r14
cmp    %r14,%rbx
je     11aa <Ptngc_comp_conv_to_rle+0x9a>
mov    0x0(%rbp,%r14,4),%eax
test   %edx,%edx
je     1160 <Ptngc_comp_conv_to_rle+0x50>
cmp    %eax,%esi
jne    1190 <Ptngc_comp_conv_to_rle+0x80>
add    $0x1,%edx
jmp    1167 <Ptngc_comp_conv_to_rle+0x57>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r13,%rdi
mov    %r12,%rcx
mov    %r15d,%r8d
call   1030 <add_rle@plt>
mov    0x0(%rbp,%r14,4),%esi
mov    $0x1,%edx
jmp    1167 <Ptngc_comp_conv_to_rle+0x57>
test   %edx,%edx
mov    0x10(%rsp),%rbx
je     11c3 <Ptngc_comp_conv_to_rle+0xb3>
lea    0xc(%rsp),%rcx
mov    %r13,%rdi
mov    %r15d,%r8d
call   1030 <add_rle@plt>
mov    0xc(%rsp),%eax
mov    %eax,(%rbx)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @Ptngc_comp_conv_to_rle(i32* %0, i32 %1, i32* %2, i32* %3, i32 %4) {
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32* %0, i32** %6
store i32 %1, i32* %7
store i32* %2, i32** %8
store i32* %3, i32** %9
store i32 %4, i32* %10
store i32 0, i32* %12
store i32 0, i32* %13
store i32 -1, i32* %14
store i32 0, i32* %11
br label %15
15: ; preds = %52, %5
%16 = load i32, i32* %11
%17 = load i32, i32* %7
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %55
19: ; preds = %15
%20 = load i32, i32* %13
%21 = icmp ne i32 %20, 0
br i1 %21, label %28, label %22
22: ; preds = %19
%23 = load i32*, i32** %6
%24 = load i32, i32* %11
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %23, i64 %25
%27 = load i32, i32* %26
store i32 %27, i32* %14
store i32 1, i32* %13
br label %51
28: ; preds = %19
%29 = load i32, i32* %14
%30 = load i32*, i32** %6
%31 = load i32, i32* %11
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %30, i64 %32
%34 = load i32, i32* %33
%35 = icmp eq i32 %29, %34
br i1 %35, label %36, label %39
36: ; preds = %28
%37 = load i32, i32* %13
%38 = add nsw i32 %37, 1
store i32 %38, i32* %13
br label %50
39: ; preds = %28
%40 = load i32*, i32** %8
%41 = load i32, i32* %14
%42 = load i32, i32* %13
%43 = load i32, i32* %10
%44 = call i32 @add_rle(i32* %40, i32 %41, i32 %42, i32* %12, i32 %43)
store i32 1, i32* %13
%45 = load i32*, i32** %6
%46 = load i32, i32* %11
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i32, i32* %45, i64 %47
%49 = load i32, i32* %48
store i32 %49, i32* %14
br label %50
50: ; preds = %39, %36
br label %51
51: ; preds = %50, %22
br label %52
52: ; preds = %51
%53 = load i32, i32* %11
%54 = add nsw i32 %53, 1
store i32 %54, i32* %11
br label %15
55: ; preds = %15
%56 = load i32, i32* %13
%57 = icmp ne i32 %56, 0
br i1 %57, label %58, label %64
58: ; preds = %55
%59 = load i32*, i32** %8
%60 = load i32, i32* %14
%61 = load i32, i32* %13
%62 = load i32, i32* %10
%63 = call i32 @add_rle(i32* %59, i32 %60, i32 %61, i32* %12, i32 %62)
br label %64
64: ; preds = %58, %55
%65 = load i32, i32* %12
%66 = load i32*, i32** %9
store i32 %65, i32* %66
ret void
}

LLVM IR (-O2):
define void @Ptngc_comp_conv_to_rle(i32* nocapture %0, i32 %1, i32* %2, i32* nocapture writeonly %3, i32 %4) {
%6 = alloca i32
%7 = bitcast i32* %6 to i8*
store i32 0, i32* %6
%8 = icmp sgt i32 %1, 0
br i1 %8, label %9, label %34
9: ; preds = %5
%10 = zext i32 %1 to i64
br label %11
11: ; preds = %9, %25
%12 = phi i64 [ 0, %9 ], [ %28, %25 ]
%13 = phi i32 [ -1, %9 ], [ %27, %25 ]
%14 = phi i32 [ 0, %9 ], [ %26, %25 ]
%15 = icmp eq i32 %14, 0
%16 = getelementptr inbounds i32, i32* %0, i64 %12
%17 = load i32, i32* %16
br i1 %15, label %25, label %18
18: ; preds = %11
%19 = icmp eq i32 %13, %17
br i1 %19, label %20, label %22
20: ; preds = %18
%21 = add nsw i32 %14, 1
br label %25
22: ; preds = %18
%23 = call i32 @add_rle(i32* %2, i32 %13, i32 %14, i32* %6, i32 %4)
%24 = load i32, i32* %16
br label %25
25: ; preds = %11, %22, %20
%26 = phi i32 [ %21, %20 ], [ 1, %22 ], [ 1, %11 ]
%27 = phi i32 [ %13, %20 ], [ %24, %22 ], [ %17, %11 ]
%28 = add nuw nsw i64 %12, 1
%29 = icmp eq i64 %28, %10
br i1 %29, label %30, label %11
30: ; preds = %25
%31 = icmp eq i32 %26, 0
br i1 %31, label %34, label %32
32: ; preds = %30
%33 = call i32 @add_rle(i32* %2, i32 %27, i32 %26, i32* %6, i32 %4)
br label %34
34: ; preds = %5, %32, %30
%35 = load i32, i32* %6
store i32 %35, i32* %3
ret void
}