#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__ strlen(char *);
char *strncpy(char *, char *, int);
char *strstr(char *, char *);
char *getconfstring(char *string, char *value, int length) {
  char *stringp = string;
  stringp = strstr(string, "=");
  if (stringp != (char *)NULL) {
    stringp++;
    if (strlen(stringp)) {
      return strncpy(value, stringp, length - 1);
    } else {
      return ((char *)NULL);
    }
  } else {
    return ((char *)NULL);
  }
}


x86 assembly (clang, -O0):
<getconfstring>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeaa(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11b2 <getconfstring+0x82>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
je     11a5 <getconfstring+0x75>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edx
sub    $0x1,%edx
call   1030 <strncpy@plt>
mov    %rax,-0x8(%rbp)
jmp    11ba <getconfstring+0x8a>
movq   $0x0,-0x8(%rbp)
jmp    11ba <getconfstring+0x8a>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getconfstring>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rsi,%r14
mov    $0x3d,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     1170 <getconfstring+0x40>
mov    %rax,%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %rax,%rax
je     1170 <getconfstring+0x40>
add    $0xffffffff,%ebp
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <strncpy@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"=\00"
define i8* @getconfstring(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%9 = load i8*, i8** %5
store i8* %9, i8** %8
%10 = load i8*, i8** %5
%11 = call i8* @strstr(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %11, i8** %8
%12 = load i8*, i8** %8
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %27
14: ; preds = %3
%15 = load i8*, i8** %8
%16 = getelementptr inbounds i8, i8* %15, i32 1
store i8* %16, i8** %8
%17 = load i8*, i8** %8
%18 = call i64 @strlen(i8* %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %26
20: ; preds = %14
%21 = load i8*, i8** %6
%22 = load i8*, i8** %8
%23 = load i32, i32* %7
%24 = sub nsw i32 %23, 1
%25 = call i8* @strncpy(i8* %21, i8* %22, i32 %24)
store i8* %25, i8** %4
br label %28
26: ; preds = %14
store i8* null, i8** %4
br label %28
27: ; preds = %3
store i8* null, i8** %4
br label %28
28: ; preds = %27, %26, %20
%29 = load i8*, i8** %4
ret i8* %29
}

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