#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__ memchr(char const *, char, size_t);
int /*<<< orphan*/ memcpy(char *, char const *, size_t);
void config_set(char *szDestination, const char *szInput, size_t cbExpected) {
  const char *pchNil;
  if (szInput == NULL) {
    return;
  }
  pchNil = (const char *)memchr(szInput, '\0', cbExpected + 1);
  if (pchNil != szInput + cbExpected) {
    return;
  }
  memcpy(szDestination, szInput, cbExpected);
  szDestination[cbExpected] = '\0';
}


x86 assembly (clang, -O0):
<config_set>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1144 <config_set+0x24>
jmp    1192 <config_set+0x72>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
add    $0x1,%rdx
xor    %esi,%esi
call   1030 <memchr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
add    -0x18(%rbp),%rcx
cmp    %rcx,%rax
je     1175 <config_set+0x55>
jmp    1192 <config_set+0x72>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<config_set>:
push   %r15
push   %r14
push   %rbx
test   %rsi,%rsi
je     115d <config_set+0x3d>
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r14
add    $0x1,%rdx
mov    %rsi,%rdi
xor    %esi,%esi
call   1030 <memchr@plt>
lea    (%rbx,%r15,1),%rcx
cmp    %rax,%rcx
jne    115d <config_set+0x3d>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1040 <memcpy@plt>
movb   $0x0,(%r14,%r15,1)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @config_set(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%8 = load i8*, i8** %5
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %11
10: ; preds = %3
br label %31
11: ; preds = %3
%12 = load i8*, i8** %5
%13 = load i64, i64* %6
%14 = add i64 %13, 1
%15 = call i64 @memchr(i8* %12, i8 signext 0, i64 %14)
%16 = inttoptr i64 %15 to i8*
store i8* %16, i8** %7
%17 = load i8*, i8** %7
%18 = load i8*, i8** %5
%19 = load i64, i64* %6
%20 = getelementptr inbounds i8, i8* %18, i64 %19
%21 = icmp ne i8* %17, %20
br i1 %21, label %22, label %23
22: ; preds = %11
br label %31
23: ; preds = %11
%24 = load i8*, i8** %4
%25 = load i8*, i8** %5
%26 = load i64, i64* %6
%27 = call i32 @memcpy(i8* %24, i8* %25, i64 %26)
%28 = load i8*, i8** %4
%29 = load i64, i64* %6
%30 = getelementptr inbounds i8, i8* %28, i64 %29
store i8 0, i8* %30
br label %31
31: ; preds = %23, %22, %10
ret void
}

LLVM IR (-O2):
define void @config_set(i8* %0, i8* %1, i64 %2) {
%4 = icmp eq i8* %1, null
br i1 %4, label %14, label %5
5: ; preds = %3
%6 = add i64 %2, 1
%7 = tail call i64 @memchr(i8* %1, i8 signext 0, i64 %6)
%8 = inttoptr i64 %7 to i8*
%9 = getelementptr inbounds i8, i8* %1, i64 %2
%10 = icmp eq i8* %9, %8
br i1 %10, label %11, label %14
11: ; preds = %5
%12 = tail call i32 @memcpy(i8* %0, i8* %1, i64 %2)
%13 = getelementptr inbounds i8, i8* %0, i64 %2
store i8 0, i8* %13
br label %14
14: ; preds = %5, %3, %11
ret void
}