#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 *);
int strlen(char const *);
char *extract_opt_arg(const char *raw_opt) {
  char *space_pos = strchr(raw_opt, '=');
  char *arg = 0;
  if (space_pos) {
    arg = malloc(sizeof(char) * ((strlen(raw_opt) - (space_pos - raw_opt))));
    strcpy(arg, space_pos + 1);
  }
  return arg;
}


x86 assembly (clang, -O0):
<extract_opt_arg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x3d,%esi
call   1050 <strchr@plt>
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11aa <extract_opt_arg+0x6a>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
cltq
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%rdx
sub    %rdx,%rcx
sub    %rcx,%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0x1,%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_opt_arg>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x3d,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     1181 <extract_opt_arg+0x41>
mov    %rax,%r14
mov    %rbx,%rdi
call   1040 <strlen@plt>
sub    %r14d,%ebx
add    %eax,%ebx
mov    %ebx,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
add    $0x1,%r14
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
jmp    1183 <extract_opt_arg+0x43>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @extract_opt_arg(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 %26
9: ; preds = %1
%10 = load i8*, i8** %2
%11 = call i32 @strlen(i8* %10)
%12 = sext i32 %11 to i64
%13 = load i8*, i8** %3
%14 = load i8*, i8** %2
%15 = ptrtoint i8* %13 to i64
%16 = ptrtoint i8* %14 to i64
%17 = sub i64 %15, %16
%18 = sub nsw i64 %12, %17
%19 = mul i64 1, %18
%20 = trunc i64 %19 to i32
%21 = call i8* @malloc(i32 %20)
store i8* %21, i8** %4
%22 = load i8*, i8** %4
%23 = load i8*, i8** %3
%24 = getelementptr inbounds i8, i8* %23, i64 1
%25 = call i32 @strcpy(i8* %22, i8* %24)
br label %26
26: ; preds = %9, %1
%27 = load i8*, i8** %4
ret i8* %27
}

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