#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 */
char strlen(char const *);
int firstnot(const char *d, const char e, int first) {
  char k;
  for (k = first; k < strlen(d); k++) {
    if (d[k] != e)
      return k;
  }
  return -1;
}


x86 assembly (clang, -O0):
<firstnot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %al,%cl
mov    -0x20(%rbp),%eax
movsbl %cl,%ecx
cmp    %ecx,%eax
jge    1182 <firstnot+0x72>
mov    -0x10(%rbp),%rax
movsbq -0x19(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
movsbl -0x11(%rbp),%ecx
cmp    %ecx,%eax
je     1170 <firstnot+0x60>
movsbl -0x19(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1189 <firstnot+0x79>
jmp    1175 <firstnot+0x65>
mov    -0x19(%rbp),%al
add    $0x1,%al
mov    %al,-0x19(%rbp)
jmp    112b <firstnot+0x1b>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<firstnot>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %esi,%r12d
mov    %rdi,%r13
call   1030 <strlen@plt>
mov    $0xffffffff,%r14d
cmp    %r15b,%al
jle    116a <firstnot+0x5a>
movsbq %r15b,%rbx
movzbl %r15b,%ebp
shl    $0x18,%ebp
nop
cmp    %r12b,0x0(%r13,%rbx,1)
jne    1164 <firstnot+0x54>
add    $0x1,%rbx
mov    %r13,%rdi
call   1030 <strlen@plt>
movsbq %al,%rax
add    $0x1000000,%ebp
cmp    %rax,%rbx
jl     1140 <firstnot+0x30>
jmp    116a <firstnot+0x5a>
sar    $0x18,%ebp
mov    %ebp,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @firstnot(i8* %0, i8 signext %1, i32 %2) {
%4 = trunc i32 %2 to i8
%5 = tail call signext i8 @strlen(i8* %0)
%6 = icmp sgt i8 %5, %4
br i1 %6, label %7, label %23
7: ; preds = %3
%8 = sext i8 %4 to i64
br label %9
9: ; preds = %7, %14
%10 = phi i64 [ %8, %7 ], [ %15, %14 ]
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, %1
br i1 %13, label %14, label %19
14: ; preds = %9
%15 = add nsw i64 %10, 1
%16 = tail call signext i8 @strlen(i8* %0)
%17 = sext i8 %16 to i64
%18 = icmp slt i64 %15, %17
br i1 %18, label %9, label %23
19: ; preds = %9
%20 = trunc i64 %10 to i32
%21 = shl i32 %20, 24
%22 = ashr exact i32 %21, 24
br label %23
23: ; preds = %14, %3, %19
%24 = phi i32 [ %22, %19 ], [ -1, %3 ], [ -1, %14 ]
ret i32 %24
}