#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 *memchr(char const *, char, size_t);
int /*<<< orphan*/ stats_log(char *, int);
int validate_carbon(const char *line, size_t len) {
  int spaces_found = 0;
  const char *p = line;
  size_t n = len;
  while (1) {
    const char *s = memchr(p, ' ', n);
    if (s == NULL) {
      break;
    }
    spaces_found++;
    n = len - (s - line) - 1;
    p = s + 1;
    if (spaces_found > 2) {
      break;
    }
  }
  if (spaces_found != 2) {
    stats_log("validate: found %d spaces in invalid carbon line", spaces_found);
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<validate_carbon>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    $0x20,%esi
call   1040 <memchr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    116d <validate_carbon+0x4d>
jmp    11b0 <validate_carbon+0x90>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    -0x10(%rbp),%rdx
sub    %rdx,%rcx
sub    %rcx,%rax
sub    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x2,-0x1c(%rbp)
jle    11ab <validate_carbon+0x8b>
jmp    11b0 <validate_carbon+0x90>
jmp    1147 <validate_carbon+0x27>
cmpl   $0x2,-0x1c(%rbp)
je     11d5 <validate_carbon+0xb5>
mov    -0x1c(%rbp),%esi
lea    0xe3c(%rip),%rdi
call   1030 <stats_log@plt>
movl   $0x1,-0x4(%rbp)
jmp    11dc <validate_carbon+0xbc>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validate_carbon>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0x20,%esi
mov    %r14,%rdx
call   1040 <memchr@plt>
test   %rax,%rax
je     1184 <validate_carbon+0x64>
add    %r14,%rbx
add    $0xffffffffffffffff,%rbx
mov    %rbx,%rdx
sub    %rax,%rdx
add    $0x1,%rax
mov    %rax,%rdi
mov    $0x20,%esi
call   1040 <memchr@plt>
test   %rax,%rax
je     1188 <validate_carbon+0x68>
sub    %rax,%rbx
add    $0x1,%rax
mov    %rax,%rdi
mov    $0x20,%esi
mov    %rbx,%rdx
call   1040 <memchr@plt>
mov    $0x3,%esi
test   %rax,%rax
jne    118d <validate_carbon+0x6d>
xor    %eax,%eax
jmp    119e <validate_carbon+0x7e>
xor    %esi,%esi
jmp    118d <validate_carbon+0x6d>
mov    $0x1,%esi
lea    0xe6c(%rip),%rdi
call   1030 <stats_log@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [49 x i8] c"validate: found %d spaces in invalid carbon line\00"
define i32 @validate_carbon(i8* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
store i8* %0, i8** %4
store i64 %1, i64* %5
store i32 0, i32* %6
%10 = load i8*, i8** %4
store i8* %10, i8** %7
%11 = load i64, i64* %5
store i64 %11, i64* %8
br label %12
12: ; preds = %2, %35
%13 = load i8*, i8** %7
%14 = load i64, i64* %8
%15 = call i8* @memchr(i8* %13, i8 signext 32, i64 %14)
store i8* %15, i8** %9
%16 = load i8*, i8** %9
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %19
18: ; preds = %12
br label %36
19: ; preds = %12
%20 = load i32, i32* %6
%21 = add nsw i32 %20, 1
store i32 %21, i32* %6
%22 = load i64, i64* %5
%23 = load i8*, i8** %9
%24 = load i8*, i8** %4
%25 = ptrtoint i8* %23 to i64
%26 = ptrtoint i8* %24 to i64
%27 = sub i64 %25, %26
%28 = sub i64 %22, %27
%29 = sub i64 %28, 1
store i64 %29, i64* %8
%30 = load i8*, i8** %9
%31 = getelementptr inbounds i8, i8* %30, i64 1
store i8* %31, i8** %7
%32 = load i32, i32* %6
%33 = icmp sgt i32 %32, 2
br i1 %33, label %34, label %35
34: ; preds = %19
br label %36
35: ; preds = %19
br label %12
36: ; preds = %34, %18
%37 = load i32, i32* %6
%38 = icmp ne i32 %37, 2
br i1 %38, label %39, label %42
39: ; preds = %36
%40 = load i32, i32* %6
%41 = call i32 @stats_log(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i32 %40)
store i32 1, i32* %3
br label %43
42: ; preds = %36
store i32 0, i32* %3
br label %43
43: ; preds = %42, %39
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
@.str = [49 x i8] c"validate: found %d spaces in invalid carbon line\00"
define i32 @validate_carbon(i8* %0, i64 %1) {
%3 = ptrtoint i8* %0 to i64
%4 = add i64 %3, -1
%5 = add i64 %4, %1
%6 = tail call i8* @memchr(i8* %0, i8 signext 32, i64 %1)
%7 = icmp eq i8* %6, null
br i1 %7, label %20, label %8
8: ; preds = %2
%9 = ptrtoint i8* %6 to i64
%10 = sub i64 %5, %9
%11 = getelementptr inbounds i8, i8* %6, i64 1
%12 = tail call i8* @memchr(i8* %11, i8 signext 32, i64 %10)
%13 = icmp eq i8* %12, null
br i1 %13, label %20, label %14
14: ; preds = %8
%15 = ptrtoint i8* %12 to i64
%16 = sub i64 %5, %15
%17 = getelementptr inbounds i8, i8* %12, i64 1
%18 = tail call i8* @memchr(i8* %17, i8 signext 32, i64 %16)
%19 = icmp eq i8* %18, null
br i1 %19, label %23, label %20
20: ; preds = %2, %8, %14
%21 = phi i32 [ 3, %14 ], [ 0, %2 ], [ 1, %8 ]
%22 = tail call i32 @stats_log(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %14, %20
%24 = phi i32 [ 1, %20 ], [ 0, %14 ]
ret i32 %24
}