#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 atoi(char *);
char *strchr(char *, char);
int extract_status(char *buff) {
  int ret = 0;
  char *pos;
  if ((pos = strchr(buff, ' ')) != NULL) {
    if (3 > (pos - buff))
      return 0;
    *pos = '\0';
    ret = atoi(buff);
    *pos = ' ';
  }
  return ret;
}


x86 assembly (clang, -O0):
<extract_status>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x20,%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     118e <extract_status+0x6e>
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
sub    %rax,%rcx
mov    $0x3,%eax
cmp    %rcx,%rax
jle    1174 <extract_status+0x54>
movl   $0x0,-0x4(%rbp)
jmp    1194 <extract_status+0x74>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   1040 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x20,(%rax)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_status>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x20,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1152 <extract_status+0x32>
mov    %rax,%rbx
sub    %r14,%rax
cmp    $0x3,%rax
jl     1152 <extract_status+0x32>
movb   $0x0,(%rbx)
mov    %r14,%rdi
call   1040 <atoi@plt>
movb   $0x20,(%rbx)
jmp    1154 <extract_status+0x34>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @extract_status(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %3
store i32 0, i32* %4
%6 = load i8*, i8** %3
%7 = call i8* @strchr(i8* %6, i8 signext 32)
store i8* %7, i8** %5
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %22
9: ; preds = %1
%10 = load i8*, i8** %5
%11 = load i8*, i8** %3
%12 = ptrtoint i8* %10 to i64
%13 = ptrtoint i8* %11 to i64
%14 = sub i64 %12, %13
%15 = icmp sgt i64 3, %14
br i1 %15, label %16, label %17
16: ; preds = %9
store i32 0, i32* %2
br label %24
17: ; preds = %9
%18 = load i8*, i8** %5
store i8 0, i8* %18
%19 = load i8*, i8** %3
%20 = call i32 @atoi(i8* %19)
store i32 %20, i32* %4
%21 = load i8*, i8** %5
store i8 32, i8* %21
br label %22
22: ; preds = %17, %1
%23 = load i32, i32* %4
store i32 %23, i32* %2
br label %24
24: ; preds = %22, %16
%25 = load i32, i32* %2
ret i32 %25
}

LLVM IR (-O2):
define i32 @extract_status(i8* %0) {
%2 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 32)
%3 = icmp eq i8* %2, null
%4 = ptrtoint i8* %2 to i64
%5 = ptrtoint i8* %0 to i64
%6 = sub i64 %4, %5
%7 = icmp slt i64 %6, 3
%8 = select i1 %3, i1 true, i1 %7
br i1 %8, label %11, label %9
9: ; preds = %1
store i8 0, i8* %2
%10 = tail call i32 @atoi(i8* %0)
store i8 32, i8* %2
br label %11
11: ; preds = %1, %9
%12 = phi i32 [ %10, %9 ], [ 0, %1 ]
ret i32 %12
}