#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 *malloc(int);
char *strchr(char const *, char);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
char *extract_opt(const char *raw_opt) {
  char *space_pos = strchr(raw_opt, '=');
  char *opt = 0;
  if (space_pos) {
    opt = malloc(sizeof(char) * ((space_pos - raw_opt) + 1));
    strncpy(opt, raw_opt, (space_pos - raw_opt));
    opt[(space_pos - raw_opt)] = '\0';
  } else {
    opt = malloc(sizeof(char) * (strlen(raw_opt) + 1));
    strcpy(opt, raw_opt);
  }
  return opt;
}


x86 assembly (clang, -O0):
<extract_opt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x3d,%esi
call   1060 <strchr@plt>
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11d1 <extract_opt+0x81>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11fb <extract_opt+0xab>
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_opt>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    $0x3d,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     118c <extract_opt+0x3c>
mov    %rax,%rbx
sub    %r14,%rbx
lea    0x1(%rbx),%edi
call   1070 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
movb   $0x0,(%r15,%rbx,1)
jmp    11aa <extract_opt+0x5a>
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
call   1070 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @extract_opt(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i8* @strchr(i8* %5, i8 signext 61)
store i8* %6, i8** %3
store i8* null, i8** %4
%7 = load i8*, i8** %3
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %35
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = load i8*, i8** %2
%12 = ptrtoint i8* %10 to i64
%13 = ptrtoint i8* %11 to i64
%14 = sub i64 %12, %13
%15 = add nsw i64 %14, 1
%16 = mul i64 1, %15
%17 = trunc i64 %16 to i32
%18 = call i8* @malloc(i32 %17)
store i8* %18, i8** %4
%19 = load i8*, i8** %4
%20 = load i8*, i8** %2
%21 = load i8*, i8** %3
%22 = load i8*, i8** %2
%23 = ptrtoint i8* %21 to i64
%24 = ptrtoint i8* %22 to i64
%25 = sub i64 %23, %24
%26 = trunc i64 %25 to i32
%27 = call i32 @strncpy(i8* %19, i8* %20, i32 %26)
%28 = load i8*, i8** %4
%29 = load i8*, i8** %3
%30 = load i8*, i8** %2
%31 = ptrtoint i8* %29 to i64
%32 = ptrtoint i8* %30 to i64
%33 = sub i64 %31, %32
%34 = getelementptr inbounds i8, i8* %28, i64 %33
store i8 0, i8* %34
br label %46
35: ; preds = %1
%36 = load i8*, i8** %2
%37 = call i32 @strlen(i8* %36)
%38 = add nsw i32 %37, 1
%39 = sext i32 %38 to i64
%40 = mul i64 1, %39
%41 = trunc i64 %40 to i32
%42 = call i8* @malloc(i32 %41)
store i8* %42, i8** %4
%43 = load i8*, i8** %4
%44 = load i8*, i8** %2
%45 = call i32 @strcpy(i8* %43, i8* %44)
br label %46
46: ; preds = %35, %9
%47 = load i8*, i8** %4
ret i8* %47
}

LLVM IR (-O2):
define i8* @extract_opt(i8* %0) {
%2 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 61)
%3 = icmp eq i8* %2, null
br i1 %3, label %13, label %4
4: ; preds = %1
%5 = ptrtoint i8* %2 to i64
%6 = ptrtoint i8* %0 to i64
%7 = sub i64 %5, %6
%8 = trunc i64 %7 to i32
%9 = add i32 %8, 1
%10 = tail call i8* @malloc(i32 %9)
%11 = tail call i32 @strncpy(i8* %10, i8* %0, i32 %8)
%12 = getelementptr inbounds i8, i8* %10, i64 %7
store i8 0, i8* %12
br label %18
13: ; preds = %1
%14 = tail call i32 @strlen(i8* %0)
%15 = add nsw i32 %14, 1
%16 = tail call i8* @malloc(i32 %15)
%17 = tail call i32 @strcpy(i8* %16, i8* %0)
br label %18
18: ; preds = %13, %4
%19 = phi i8* [ %10, %4 ], [ %16, %13 ]
ret i8* %19
}