#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__ malloc(int);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *cloneFirstWord(char *str) {
  char *start = 0;
  char *end = 0;
  char *word;
  while (!end) {
    switch (*str) {
    case '>':
    case '<':
    case 0:
      end = str - 1;
      break;
    case ' ':
      if (start)
        end = str - 1;
      break;
    default:
      if (!start)
        start = str;
      break;
    }
    str++;
  }
  if (start == 0)
    return 0;
  word = (char *)malloc(end - start + 2);
  strncpy(word, start, ((int)(end - start) + 1));
  word[(int)((end - start) + 1)] = 0;
  return word;
}


x86 assembly (clang, -O0):
<cloneFirstWord>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1153 <cloneFirstWord+0x33>
jmp    11f3 <cloneFirstWord+0xd3>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x2c(%rbp)
test   %eax,%eax
je     119d <cloneFirstWord+0x7d>
jmp    116a <cloneFirstWord+0x4a>
mov    -0x2c(%rbp),%eax
sub    $0x20,%eax
je     11ae <cloneFirstWord+0x8e>
jmp    117b <cloneFirstWord+0x5b>
mov    -0x2c(%rbp),%eax
sub    $0x3c,%eax
je     119d <cloneFirstWord+0x7d>
jmp    118c <cloneFirstWord+0x6c>
mov    -0x2c(%rbp),%eax
sub    $0x3e,%eax
jne    11ca <cloneFirstWord+0xaa>
jmp    119d <cloneFirstWord+0x7d>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    11e2 <cloneFirstWord+0xc2>
cmpq   $0x0,-0x18(%rbp)
je     11c5 <cloneFirstWord+0xa5>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    11e2 <cloneFirstWord+0xc2>
cmpq   $0x0,-0x18(%rbp)
jne    11dd <cloneFirstWord+0xbd>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    11e2 <cloneFirstWord+0xc2>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    113c <cloneFirstWord+0x1c>
cmpq   $0x0,-0x18(%rbp)
jne    120b <cloneFirstWord+0xeb>
movq   $0x0,-0x8(%rbp)
jmp    1264 <cloneFirstWord+0x144>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
add    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
add    $0x1,%edx
call   1030 <strncpy@plt>
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rdx
sub    %rdx,%rcx
add    $0x1,%rcx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cloneFirstWord>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    %rdi,%r12
shl    $0x20,%r12
xor    %ebx,%ebx
movabs $0x100000000,%rax
mov    %rdi,%rcx
jmp    1166 <cloneFirstWord+0x46>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
test   %edx,%edx
je     118a <cloneFirstWord+0x6a>
test   %rbx,%rbx
cmove  %rcx,%rbx
add    $0x1,%rcx
add    %rax,%r12
add    $0x1,%r14d
movsbl (%rcx),%edx
cmp    $0x3b,%edx
jg     1180 <cloneFirstWord+0x60>
cmp    $0x20,%edx
jne    1150 <cloneFirstWord+0x30>
test   %rbx,%rbx
jne    118f <cloneFirstWord+0x6f>
xor    %ebx,%ebx
jmp    115b <cloneFirstWord+0x3b>
nopl   0x0(%rax)
cmp    $0x3c,%edx
je     118a <cloneFirstWord+0x6a>
cmp    $0x3e,%edx
jne    1154 <cloneFirstWord+0x34>
test   %rbx,%rbx
je     11be <cloneFirstWord+0x9e>
sub    %ebx,%r14d
lea    0x1(%r14),%edi
call   1040 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1030 <strncpy@plt>
shl    $0x20,%rbx
sub    %rbx,%r12
sar    $0x20,%r12
movb   $0x0,(%r15,%r12,1)
jmp    11c1 <cloneFirstWord+0xa1>
xor    %r15d,%r15d
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @cloneFirstWord(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
store i8* null, i8** %4
store i8* null, i8** %5
br label %7
7: ; preds = %31, %1
%8 = load i8*, i8** %5
%9 = icmp ne i8* %8, null
%10 = xor i1 %9, true
br i1 %10, label %11, label %34
11: ; preds = %7
%12 = load i8*, i8** %3
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
switch i32 %14, label %25 [
i32 62, label %15
i32 60, label %15
i32 0, label %15
i32 32, label %18
]
15: ; preds = %11, %11, %11
%16 = load i8*, i8** %3
%17 = getelementptr inbounds i8, i8* %16, i64 -1
store i8* %17, i8** %5
br label %31
18: ; preds = %11
%19 = load i8*, i8** %4
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load i8*, i8** %3
%23 = getelementptr inbounds i8, i8* %22, i64 -1
store i8* %23, i8** %5
br label %24
24: ; preds = %21, %18
br label %31
25: ; preds = %11
%26 = load i8*, i8** %4
%27 = icmp ne i8* %26, null
br i1 %27, label %30, label %28
28: ; preds = %25
%29 = load i8*, i8** %3
store i8* %29, i8** %4
br label %30
30: ; preds = %28, %25
br label %31
31: ; preds = %30, %24, %15
%32 = load i8*, i8** %3
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %3
br label %7
34: ; preds = %7
%35 = load i8*, i8** %4
%36 = icmp eq i8* %35, null
br i1 %36, label %37, label %38
37: ; preds = %34
store i8* null, i8** %2
br label %69
38: ; preds = %34
%39 = load i8*, i8** %5
%40 = load i8*, i8** %4
%41 = ptrtoint i8* %39 to i64
%42 = ptrtoint i8* %40 to i64
%43 = sub i64 %41, %42
%44 = add nsw i64 %43, 2
%45 = trunc i64 %44 to i32
%46 = call i64 @malloc(i32 %45)
%47 = inttoptr i64 %46 to i8*
store i8* %47, i8** %6
%48 = load i8*, i8** %6
%49 = load i8*, i8** %4
%50 = load i8*, i8** %5
%51 = load i8*, i8** %4
%52 = ptrtoint i8* %50 to i64
%53 = ptrtoint i8* %51 to i64
%54 = sub i64 %52, %53
%55 = trunc i64 %54 to i32
%56 = add nsw i32 %55, 1
%57 = call i32 @strncpy(i8* %48, i8* %49, i32 %56)
%58 = load i8*, i8** %6
%59 = load i8*, i8** %5
%60 = load i8*, i8** %4
%61 = ptrtoint i8* %59 to i64
%62 = ptrtoint i8* %60 to i64
%63 = sub i64 %61, %62
%64 = add nsw i64 %63, 1
%65 = trunc i64 %64 to i32
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8, i8* %58, i64 %66
store i8 0, i8* %67
%68 = load i8*, i8** %6
store i8* %68, i8** %2
br label %69
69: ; preds = %38, %37
%70 = load i8*, i8** %2
ret i8* %70
}

LLVM IR (-O2):
define i8* @cloneFirstWord(i8* %0) {
br label %2
2: ; preds = %12, %1
%3 = phi i8* [ null, %1 ], [ %13, %12 ]
%4 = phi i8* [ %0, %1 ], [ %14, %12 ]
%5 = load i8, i8* %4
%6 = sext i8 %5 to i32
switch i32 %6, label %9 [
i32 62, label %15
i32 60, label %15
i32 0, label %15
i32 32, label %7
]
7: ; preds = %2
%8 = icmp eq i8* %3, null
br i1 %8, label %12, label %17
9: ; preds = %2
%10 = icmp eq i8* %3, null
%11 = select i1 %10, i8* %4, i8* %3
br label %12
12: ; preds = %7, %9
%13 = phi i8* [ %11, %9 ], [ null, %7 ]
%14 = getelementptr inbounds i8, i8* %4, i64 1
br label %2
15: ; preds = %2, %2, %2
%16 = icmp eq i8* %3, null
br i1 %16, label %32, label %17
17: ; preds = %7, %15
%18 = getelementptr inbounds i8, i8* %4, i64 -1
%19 = ptrtoint i8* %18 to i64
%20 = ptrtoint i8* %3 to i64
%21 = sub i64 %19, %20
%22 = trunc i64 %21 to i32
%23 = add i32 %22, 2
%24 = tail call i64 @malloc(i32 %23)
%25 = inttoptr i64 %24 to i8*
%26 = add nsw i32 %22, 1
%27 = tail call i32 @strncpy(i8* %25, i8* %3, i32 %26)
%28 = shl i64 %21, 32
%29 = add i64 %28, 4294967296
%30 = ashr exact i64 %29, 32
%31 = getelementptr inbounds i8, i8* %25, i64 %30
store i8 0, i8* %31
br label %32
32: ; preds = %15, %17
%33 = phi i8* [ %25, %17 ], [ null, %15 ]
ret i8* %33
}