#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 findchanging(unsigned char const *, int, int);
int getbit(unsigned char const *, int);
int findchangingcolor(const unsigned char *line, int x, int w, int color) {
  if (line == 0)
    return w;
  x = findchanging(line, x, w);
  if (x < w && getbit(line, x) != color)
    x = findchanging(line, x, w);
  return x;
}


x86 assembly (clang, -O0):
<findchangingcolor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    114b <findchangingcolor+0x2b>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1196 <findchangingcolor+0x76>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1040 <findchanging@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1190 <findchangingcolor+0x70>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <getbit@plt>
cmp    -0x1c(%rbp),%eax
je     1190 <findchangingcolor+0x70>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1040 <findchanging@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findchangingcolor>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
test   %rdi,%rdi
je     1155 <findchangingcolor+0x35>
mov    %ecx,%r14d
mov    %rdi,%rbx
mov    %ebp,%edx
call   1040 <findchanging@plt>
mov    %eax,%r15d
cmp    %ebp,%eax
jge    1152 <findchangingcolor+0x32>
mov    %rbx,%rdi
mov    %r15d,%esi
call   1030 <getbit@plt>
cmp    %r14d,%eax
jne    1162 <findchangingcolor+0x42>
mov    %r15d,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %ebp,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <findchanging@plt>

LLVM IR (-O0):
define i32 @findchangingcolor(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%10 = load i8*, i8** %6
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %14
12: ; preds = %4
%13 = load i32, i32* %8
store i32 %13, i32* %5
br label %35
14: ; preds = %4
%15 = load i8*, i8** %6
%16 = load i32, i32* %7
%17 = load i32, i32* %8
%18 = call i32 @findchanging(i8* %15, i32 %16, i32 %17)
store i32 %18, i32* %7
%19 = load i32, i32* %7
%20 = load i32, i32* %8
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %33
22: ; preds = %14
%23 = load i8*, i8** %6
%24 = load i32, i32* %7
%25 = call i32 @getbit(i8* %23, i32 %24)
%26 = load i32, i32* %9
%27 = icmp ne i32 %25, %26
br i1 %27, label %28, label %33
28: ; preds = %22
%29 = load i8*, i8** %6
%30 = load i32, i32* %7
%31 = load i32, i32* %8
%32 = call i32 @findchanging(i8* %29, i32 %30, i32 %31)
store i32 %32, i32* %7
br label %33
33: ; preds = %28, %22, %14
%34 = load i32, i32* %7
store i32 %34, i32* %5
br label %35
35: ; preds = %33, %12
%36 = load i32, i32* %5
ret i32 %36
}

LLVM IR (-O2):
define i32 @findchangingcolor(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = icmp eq i8* %0, null
br i1 %5, label %14, label %6
6: ; preds = %4
%7 = tail call i32 @findchanging(i8* %0, i32 %1, i32 %2)
%8 = icmp slt i32 %7, %2
br i1 %8, label %9, label %14
9: ; preds = %6
%10 = tail call i32 @getbit(i8* %0, i32 %7)
%11 = icmp eq i32 %10, %3
br i1 %11, label %14, label %12
12: ; preds = %9
%13 = tail call i32 @findchanging(i8* %0, i32 %7, i32 %2)
br label %14
14: ; preds = %6, %9, %12, %4
%15 = phi i32 [ %2, %4 ], [ %13, %12 ], [ %7, %9 ], [ %7, %6 ]
ret i32 %15
}