#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 /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
char *strchr(char *, char);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int __optval(char *buf, char *optval) {
  char *t;
  int len;
  memset(optval, 0, 256);
  t = strchr(buf, '=');
  if (t != NULL) {
    len = strlen(buf) - (t - buf + 1);
    strncpy(optval, t + 1, len);
  } else {
    len = -1;
    optval[0] = '\0';
  }
  return len;
}


x86 assembly (clang, -O0):
<__optval>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
mov    -0x8(%rbp),%rdi
mov    $0x3d,%esi
call   1050 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11b6 <__optval+0x76>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
cltq
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rdx
sub    %rdx,%rcx
add    $0x1,%rcx
sub    %rcx,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    $0x1,%rsi
mov    -0x1c(%rbp),%edx
call   1030 <strncpy@plt>
jmp    11c4 <__optval+0x84>
movl   $0xffffffff,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__optval>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
mov    %rbx,%rdi
mov    $0x3d,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     1193 <__optval+0x53>
mov    %rax,%r15
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r15d,%ecx
not    %ecx
add    %ecx,%ebx
add    %eax,%ebx
add    $0x1,%r15
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
jmp    119c <__optval+0x5c>
movb   $0x0,(%r14)
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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