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


x86 assembly (clang, -O0):
<__optname>:
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   1050 <memset@plt>
mov    -0x8(%rbp),%rdi
mov    $0x3d,%esi
call   1040 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1190 <__optname+0x60>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <strncpy@plt>
jmp    119e <__optname+0x6e>
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):
<__optname>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsi,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
mov    %r15,%rdi
mov    $0x3d,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1171 <__optname+0x41>
mov    %rax,%rbx
sub    %r15d,%ebx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
jmp    117a <__optname+0x4a>
movb   $0x0,(%r14)
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @__optname(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 %24
13: ; preds = %2
%14 = load i8*, i8** %5
%15 = load i8*, i8** %3
%16 = ptrtoint i8* %14 to i64
%17 = ptrtoint i8* %15 to i64
%18 = sub i64 %16, %17
%19 = trunc i64 %18 to i32
store i32 %19, i32* %6
%20 = load i8*, i8** %4
%21 = load i8*, i8** %3
%22 = load i32, i32* %6
%23 = call i32 @strncpy(i8* %20, i8* %21, i32 %22)
br label %27
24: ; preds = %2
store i32 -1, i32* %6
%25 = load i8*, i8** %4
%26 = getelementptr inbounds i8, i8* %25, i64 0
store i8 0, i8* %26
br label %27
27: ; preds = %24, %13
%28 = load i32, i32* %6
ret i32 %28
}

LLVM IR (-O2):
define i32 @__optname(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 %12, label %6
6: ; preds = %2
%7 = ptrtoint i8* %4 to i64
%8 = ptrtoint i8* %0 to i64
%9 = sub i64 %7, %8
%10 = trunc i64 %9 to i32
%11 = tail call i32 @strncpy(i8* %1, i8* %0, i32 %10)
br label %13
12: ; preds = %2
store i8 0, i8* %1
br label %13
13: ; preds = %12, %6
%14 = phi i32 [ %10, %6 ], [ -1, %12 ]
ret i32 %14
}