#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 strcspn(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, int);
scalar_t__ strncmp(char *, char *, int);
int get_val(char *cfgline, char *keyTest, char *destVal) {
  int linelen = strcspn(cfgline, "\n\r");
  int keylen = strlen(keyTest);
  if (strncmp(cfgline, keyTest, keylen) != 0)
    return 0;
  destVal[0] = '\0';
  strncat(destVal, cfgline + keylen, linelen - keylen);
  return 1;
}


x86 assembly (clang, -O0):
<get_val>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea1(%rip),%rsi
call   1060 <strcspn@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     1199 <get_val+0x59>
movl   $0x0,-0x4(%rbp)
jmp    11c1 <get_val+0x81>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x28(%rbp),%rax
add    %rax,%rsi
mov    -0x24(%rbp),%edx
sub    -0x28(%rbp),%edx
call   1050 <strncat@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_val>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbp
mov    %rdi,%rbx
lea    0xea8(%rip),%rsi
call   1060 <strcspn@plt>
mov    %eax,%r15d
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %eax,%r12d
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    11a2 <get_val+0x62>
movb   $0x0,(%r14)
movslq %r12d,%rax
add    %rax,%rbx
sub    %r12d,%r15d
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1050 <strncat@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"\0A\0D\00"
define i32 @get_val(i8* %0, i8* %1, i8* %2) {
%4 = tail call i32 @strcspn(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @strlen(i8* %1)
%6 = tail call i64 @strncmp(i8* %0, i8* %1, i32 %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %3
store i8 0, i8* %2
%9 = sext i32 %5 to i64
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = sub nsw i32 %4, %5
%12 = tail call i32 @strncat(i8* %2, i8* %10, i32 %11)
br label %13
13: ; preds = %3, %8
%14 = phi i32 [ 1, %8 ], [ 0, %3 ]
ret i32 %14
}