#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 */
scalar_t__ _is_sep(char const, char const *);
char *malloc(int);
int /*<<< orphan*/ memcpy(char *, char const *, int);
int /*<<< orphan*/ perror(char *);
char *_extract_word(const char *data, const char *sep) {
  char *word;
  int len;
  for (len = 0; _is_sep(data[len], sep) == 0; len++)
    ;
  word = malloc(sizeof(char) * (len + 1));
  if (!word) {
    perror("malloc");
    return (NULL);
  }
  memcpy(word, data, len);
  word[len] = '\0';
  return (word);
}


x86 assembly (clang, -O0):
<_extract_word>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    -0x18(%rbp),%rsi
movsbl %al,%edi
call   1060 <_is_sep@plt>
cmp    $0x0,%rax
jne    118b <_extract_word+0x4b>
jmp    117d <_extract_word+0x3d>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1157 <_extract_word+0x17>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11c6 <_extract_word+0x86>
lea    0xe4c(%rip),%rdi
call   1050 <perror@plt>
movq   $0x0,-0x8(%rbp)
jmp    11ea <_extract_word+0xaa>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1030 <memcpy@plt>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_extract_word>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
mov    $0xffffffffffffffff,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
movsbl 0x1(%r14,%rbx,1),%edi
mov    %r15,%rsi
call   1060 <_is_sep@plt>
add    $0x1,%rbx
test   %rax,%rax
je     1160 <_extract_word+0x20>
lea    0x1(%rbx),%edi
call   1040 <malloc@plt>
mov    %rax,%r15
test   %rax,%rax
je     11ab <_extract_word+0x6b>
mov    %ebx,%r12d
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <memcpy@plt>
movb   $0x0,(%r15,%r12,1)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xe4e(%rip),%rdi
call   1050 <perror@plt>
jmp    119c <_extract_word+0x5c>

LLVM IR (-O0):
@.str = [7 x i8] c"malloc\00"
define i8* @_extract_word(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 0, i32* %7
br label %8
8: ; preds = %18, %2
%9 = load i8*, i8** %4
%10 = load i32, i32* %7
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %9, i64 %11
%13 = load i8, i8* %12
%14 = load i8*, i8** %5
%15 = call i64 @_is_sep(i8 signext %13, i8* %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %8
br label %18
18: ; preds = %17
%19 = load i32, i32* %7
%20 = add nsw i32 %19, 1
store i32 %20, i32* %7
br label %8
21: ; preds = %8
%22 = load i32, i32* %7
%23 = add nsw i32 %22, 1
%24 = sext i32 %23 to i64
%25 = mul i64 1, %24
%26 = trunc i64 %25 to i32
%27 = call i8* @malloc(i32 %26)
store i8* %27, i8** %6
%28 = load i8*, i8** %6
%29 = icmp ne i8* %28, null
br i1 %29, label %32, label %30
30: ; preds = %21
%31 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %3
br label %42
32: ; preds = %21
%33 = load i8*, i8** %6
%34 = load i8*, i8** %4
%35 = load i32, i32* %7
%36 = call i32 @memcpy(i8* %33, i8* %34, i32 %35)
%37 = load i8*, i8** %6
%38 = load i32, i32* %7
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
store i8 0, i8* %40
%41 = load i8*, i8** %6
store i8* %41, i8** %3
br label %42
42: ; preds = %32, %30
%43 = load i8*, i8** %3
ret i8* %43
}

LLVM IR (-O2):
@.str = [7 x i8] c"malloc\00"
define i8* @_extract_word(i8* %0, i8* %1) {
br label %3
3: ; preds = %3, %2
%4 = phi i64 [ %9, %3 ], [ 0, %2 ]
%5 = getelementptr inbounds i8, i8* %0, i64 %4
%6 = load i8, i8* %5
%7 = tail call i64 @_is_sep(i8 signext %6, i8* %1)
%8 = icmp eq i64 %7, 0
%9 = add nuw i64 %4, 1
br i1 %8, label %3, label %10
10: ; preds = %3
%11 = trunc i64 %4 to i32
%12 = add nuw nsw i32 %11, 1
%13 = tail call i8* @malloc(i32 %12)
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %21
17: ; preds = %10
%18 = and i64 %4, 4294967295
%19 = tail call i32 @memcpy(i8* %13, i8* %0, i32 %11)
%20 = getelementptr inbounds i8, i8* %13, i64 %18
store i8 0, i8* %20
br label %21
21: ; preds = %17, %15
ret i8* %13
}