#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 strlen(char *);
int locate_next_space(char *s, int low) {
  int i;
  for (i = low; i < strlen(s); i++)
    if (s[i] == ' ')
      return i;
  return -1;
}


x86 assembly (clang, -O0):
<locate_next_space>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jge    1174 <locate_next_space+0x64>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jne    1161 <locate_next_space+0x51>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    117b <locate_next_space+0x6b>
jmp    1166 <locate_next_space+0x56>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1125 <locate_next_space+0x15>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<locate_next_space>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    $0xffffffff,%r14d
cmp    %ebp,%eax
jle    114e <locate_next_space+0x3e>
movslq %ebp,%rbp
nopl   0x0(%rax,%rax,1)
cmpb   $0x20,(%rbx,%rbp,1)
je     114b <locate_next_space+0x3b>
add    $0x1,%rbp
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbp
jl     1130 <locate_next_space+0x20>
jmp    114e <locate_next_space+0x3e>
mov    %ebp,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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