#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 getbit(unsigned char const *, int);
int find_changing(const unsigned char *line, int x, int w) {
  int a, b;
  if (!line)
    return w;
  if (x == -1) {
    a = 0;
    x = 0;
  } else {
    a = getbit(line, x);
    x++;
  }
  while (x < w) {
    b = getbit(line, x);
    if (a != b)
      break;
    x++;
  }
  return x;
}


x86 assembly (clang, -O0):
<find_changing>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1138 <find_changing+0x28>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b2 <find_changing+0xa2>
cmpl   $0xffffffff,-0x14(%rbp)
jne    1155 <find_changing+0x45>
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x14(%rbp)
jmp    116d <find_changing+0x5d>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <getbit@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1172 <find_changing+0x62>
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11ac <find_changing+0x9c>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <getbit@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
je     119e <find_changing+0x8e>
jmp    11ac <find_changing+0x9c>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1172 <find_changing+0x62>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_changing>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
test   %rdi,%rdi
je     116c <find_changing+0x5c>
mov    %esi,%ebp
mov    %rdi,%rbx
cmp    $0xffffffff,%esi
je     1140 <find_changing+0x30>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1030 <getbit@plt>
mov    %eax,%r15d
add    $0x1,%ebp
cmp    %r14d,%ebp
jge    1169 <find_changing+0x59>
jmp    1150 <find_changing+0x40>
xor    %ebp,%ebp
xor    %r15d,%r15d
cmp    %r14d,%ebp
jge    1169 <find_changing+0x59>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %ebp,%esi
call   1030 <getbit@plt>
cmp    %eax,%r15d
jne    1169 <find_changing+0x59>
add    $0x1,%ebp
cmp    %ebp,%r14d
jne    1150 <find_changing+0x40>
jmp    116c <find_changing+0x5c>
mov    %ebp,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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