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


x86 assembly (clang, -O0):
<find_changing_color>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    114b <find_changing_color+0x2b>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ca <find_changing_color+0xaa>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0x14(%rbp)
jg     1167 <find_changing_color+0x47>
cmpl   $0x0,-0x1c(%rbp)
jne    1172 <find_changing_color+0x52>
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    117f <find_changing_color+0x5f>
mov    $0xffffffff,%eax
mov    %eax,-0x2c(%rbp)
jmp    117f <find_changing_color+0x5f>
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1030 <find_changing@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11c4 <find_changing_color+0xa4>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <getbit@plt>
cmp    -0x1c(%rbp),%eax
je     11c4 <find_changing_color+0xa4>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1030 <find_changing@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_changing_color>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
test   %rdi,%rdi
je     1164 <find_changing_color+0x44>
mov    %ecx,%r14d
mov    %rdi,%rbx
mov    %ecx,%eax
neg    %eax
sbb    %eax,%eax
or     %esi,%eax
test   %esi,%esi
cmovg  %esi,%eax
mov    %eax,%esi
mov    %ebp,%edx
call   1030 <find_changing@plt>
mov    %eax,%r15d
cmp    %ebp,%eax
jge    1161 <find_changing_color+0x41>
mov    %rbx,%rdi
mov    %r15d,%esi
call   1040 <getbit@plt>
cmp    %r14d,%eax
jne    1171 <find_changing_color+0x51>
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    1030 <find_changing@plt>

LLVM IR (-O0):
define i32 @find_changing_color(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 ne i8* %10, null
br i1 %11, label %14, label %12
12: ; preds = %4
%13 = load i32, i32* %8
store i32 %13, i32* %5
br label %44
14: ; preds = %4
%15 = load i8*, i8** %6
%16 = load i32, i32* %7
%17 = icmp sgt i32 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %14
%19 = load i32, i32* %9
%20 = icmp ne i32 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %18, %14
%22 = load i32, i32* %7
br label %24
23: ; preds = %18
br label %24
24: ; preds = %23, %21
%25 = phi i32 [ %22, %21 ], [ -1, %23 ]
%26 = load i32, i32* %8
%27 = call i32 @find_changing(i8* %15, i32 %25, i32 %26)
store i32 %27, i32* %7
%28 = load i32, i32* %7
%29 = load i32, i32* %8
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %42
31: ; preds = %24
%32 = load i8*, i8** %6
%33 = load i32, i32* %7
%34 = call i32 @getbit(i8* %32, i32 %33)
%35 = load i32, i32* %9
%36 = icmp ne i32 %34, %35
br i1 %36, label %37, label %42
37: ; preds = %31
%38 = load i8*, i8** %6
%39 = load i32, i32* %7
%40 = load i32, i32* %8
%41 = call i32 @find_changing(i8* %38, i32 %39, i32 %40)
store i32 %41, i32* %7
br label %42
42: ; preds = %37, %31, %24
%43 = load i32, i32* %7
store i32 %43, i32* %5
br label %44
44: ; preds = %42, %12
%45 = load i32, i32* %5
ret i32 %45
}

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