#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 */
unsigned long _tga_write_get_pixel(unsigned char *, int);
long _tga_write_count_diff_pixels(unsigned char *ucp_will_encode,
                                  int l_samples_per_pixel, long l_pixel_count) {
  unsigned long ul_pixel;
  unsigned long ul_next_pixel = 0;
  long l_count;
  l_count = 0;
  if ((long)1 == l_pixel_count)
    return l_pixel_count;
  ul_pixel = _tga_write_get_pixel(ucp_will_encode, l_samples_per_pixel);
  while ((long)1 < l_pixel_count) {
    ucp_will_encode += l_samples_per_pixel;
    ul_next_pixel = _tga_write_get_pixel(ucp_will_encode, l_samples_per_pixel);
    if (ul_next_pixel == ul_pixel)
      break;
    ul_pixel = ul_next_pixel;
    ++l_count;
    --l_pixel_count;
  }
  if (ul_next_pixel == ul_pixel)
    return l_count;
  return l_count + 1;
}


x86 assembly (clang, -O0):
<_tga_write_count_diff_pixels>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    $0x1,%eax
cmp    -0x20(%rbp),%rax
jne    114f <_tga_write_count_diff_pixels+0x3f>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ee <_tga_write_count_diff_pixels+0xde>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <_tga_write_get_pixel@plt>
mov    %rax,-0x28(%rbp)
mov    $0x1,%eax
cmp    -0x20(%rbp),%rax
jge    11c7 <_tga_write_count_diff_pixels+0xb7>
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <_tga_write_get_pixel@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
jne    11a2 <_tga_write_count_diff_pixels+0x92>
jmp    11c7 <_tga_write_count_diff_pixels+0xb7>
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    115f <_tga_write_count_diff_pixels+0x4f>
mov    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
jne    11e2 <_tga_write_count_diff_pixels+0xd2>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ee <_tga_write_count_diff_pixels+0xde>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_tga_write_count_diff_pixels>:
mov    $0x1,%ecx
cmp    $0x1,%rdx
je     1199 <_tga_write_count_diff_pixels+0x89>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %esi,%r14d
mov    %rdi,%rbp
call   1030 <_tga_write_get_pixel@plt>
mov    %rax,%r12
cmp    $0x2,%r15
jl     1177 <_tga_write_count_diff_pixels+0x67>
movslq %r14d,%r13
add    $0xffffffffffffffff,%r15
add    %r13,%rbp
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    %rbp,%rdi
mov    %r14d,%esi
call   1030 <_tga_write_get_pixel@plt>
cmp    %r12,%rax
je     117d <_tga_write_count_diff_pixels+0x6d>
add    $0x1,%rbx
add    %r13,%rbp
mov    %rax,%r12
cmp    %rbx,%r15
jne    1150 <_tga_write_count_diff_pixels+0x40>
mov    %rax,%r12
mov    %r15,%rbx
jmp    1180 <_tga_write_count_diff_pixels+0x70>
xor    %ebx,%ebx
xor    %eax,%eax
jmp    1180 <_tga_write_count_diff_pixels+0x70>
mov    %r12,%rax
xor    %ecx,%ecx
cmp    %r12,%rax
setne  %cl
add    %rbx,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
mov    %rcx,%rax
ret

LLVM IR (-O0):
define i64 @_tga_write_count_diff_pixels(i8* %0, i32 %1, i64 %2) {
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
store i8* %0, i8** %5
store i32 %1, i32* %6
store i64 %2, i64* %7
store i64 0, i64* %9
store i64 0, i64* %10
%11 = load i64, i64* %7
%12 = icmp eq i64 1, %11
br i1 %12, label %13, label %15
13: ; preds = %3
%14 = load i64, i64* %7
store i64 %14, i64* %4
br label %49
15: ; preds = %3
%16 = load i8*, i8** %5
%17 = load i32, i32* %6
%18 = call i64 @_tga_write_get_pixel(i8* %16, i32 %17)
store i64 %18, i64* %8
br label %19
19: ; preds = %34, %15
%20 = load i64, i64* %7
%21 = icmp slt i64 1, %20
br i1 %21, label %22, label %40
22: ; preds = %19
%23 = load i32, i32* %6
%24 = load i8*, i8** %5
%25 = sext i32 %23 to i64
%26 = getelementptr inbounds i8, i8* %24, i64 %25
store i8* %26, i8** %5
%27 = load i8*, i8** %5
%28 = load i32, i32* %6
%29 = call i64 @_tga_write_get_pixel(i8* %27, i32 %28)
store i64 %29, i64* %9
%30 = load i64, i64* %9
%31 = load i64, i64* %8
%32 = icmp eq i64 %30, %31
br i1 %32, label %33, label %34
33: ; preds = %22
br label %40
34: ; preds = %22
%35 = load i64, i64* %9
store i64 %35, i64* %8
%36 = load i64, i64* %10
%37 = add nsw i64 %36, 1
store i64 %37, i64* %10
%38 = load i64, i64* %7
%39 = add nsw i64 %38, -1
store i64 %39, i64* %7
br label %19
40: ; preds = %33, %19
%41 = load i64, i64* %9
%42 = load i64, i64* %8
%43 = icmp eq i64 %41, %42
br i1 %43, label %44, label %46
44: ; preds = %40
%45 = load i64, i64* %10
store i64 %45, i64* %4
br label %49
46: ; preds = %40
%47 = load i64, i64* %10
%48 = add nsw i64 %47, 1
store i64 %48, i64* %4
br label %49
49: ; preds = %46, %44, %13
%50 = load i64, i64* %4
ret i64 %50
}

LLVM IR (-O2):
define i64 @_tga_write_count_diff_pixels(i8* %0, i32 %1, i64 %2) {
%4 = icmp eq i64 %2, 1
br i1 %4, label %28, label %5
5: ; preds = %3
%6 = tail call i64 @_tga_write_get_pixel(i8* %0, i32 %1)
%7 = sext i32 %1 to i64
%8 = icmp sgt i64 %2, 1
br i1 %8, label %9, label %21
9: ; preds = %5
%10 = add nsw i64 %2, -1
br label %11
11: ; preds = %9, %18
%12 = phi i64 [ %19, %18 ], [ 0, %9 ]
%13 = phi i64 [ %16, %18 ], [ %6, %9 ]
%14 = phi i8* [ %15, %18 ], [ %0, %9 ]
%15 = getelementptr inbounds i8, i8* %14, i64 %7
%16 = tail call i64 @_tga_write_get_pixel(i8* %15, i32 %1)
%17 = icmp eq i64 %16, %13
br i1 %17, label %21, label %18
18: ; preds = %11
%19 = add nuw nsw i64 %12, 1
%20 = icmp eq i64 %19, %10
br i1 %20, label %21, label %11
21: ; preds = %18, %11, %5
%22 = phi i64 [ %6, %5 ], [ %16, %18 ], [ %13, %11 ]
%23 = phi i64 [ 0, %5 ], [ %10, %18 ], [ %12, %11 ]
%24 = phi i64 [ 0, %5 ], [ %16, %18 ], [ %13, %11 ]
%25 = icmp ne i64 %24, %22
%26 = zext i1 %25 to i64
%27 = add nuw nsw i64 %23, %26
br label %28
28: ; preds = %21, %3
%29 = phi i64 [ 1, %3 ], [ %27, %21 ]
ret i64 %29
}