#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 strlen(char const *);
int /*<<< orphan*/ strncmp(char const *, char const *, int);
int /*<<< orphan*/ strncpy(char *, char const *, int);
void readval(const char *from, const char *val, char *to) {
  int flen = strlen(val), llen = strlen(from);
  if (!strncmp(from, val, flen))
    strncpy(to, from + flen, (llen - flen) - 1);
}


x86 assembly (clang, -O0):
<readval>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    1192 <readval+0x62>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0x1c(%rbp),%rax
add    %rax,%rsi
mov    -0x20(%rbp),%edx
sub    -0x1c(%rbp),%edx
sub    $0x1,%edx
call   1030 <strncpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readval>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbp
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1050 <strlen@plt>
mov    %eax,%r12d
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,%r15d
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r12d,%edx
call   1040 <strncmp@plt>
test   %eax,%eax
je     1172 <readval+0x42>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
movslq %r12d,%rax
add    %rax,%rbx
not    %r12d
add    %r12d,%r15d
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <strncpy@plt>

LLVM IR (-O0):
define void @readval(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%9 = load i8*, i8** %5
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %7
%11 = load i8*, i8** %4
%12 = call i32 @strlen(i8* %11)
store i32 %12, i32* %8
%13 = load i8*, i8** %4
%14 = load i8*, i8** %5
%15 = load i32, i32* %7
%16 = call i32 @strncmp(i8* %13, i8* %14, i32 %15)
%17 = icmp ne i32 %16, 0
br i1 %17, label %29, label %18
18: ; preds = %3
%19 = load i8*, i8** %6
%20 = load i8*, i8** %4
%21 = load i32, i32* %7
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i32, i32* %8
%25 = load i32, i32* %7
%26 = sub nsw i32 %24, %25
%27 = sub nsw i32 %26, 1
%28 = call i32 @strncpy(i8* %19, i8* %23, i32 %27)
br label %29
29: ; preds = %18, %3
ret void
}

LLVM IR (-O2):
define void @readval(i8* %0, i8* %1, i8* %2) {
%4 = tail call i32 @strlen(i8* %1)
%5 = tail call i32 @strlen(i8* %0)
%6 = tail call i32 @strncmp(i8* %0, i8* %1, i32 %4)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %14
8: ; preds = %3
%9 = sext i32 %4 to i64
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = xor i32 %4, -1
%12 = add i32 %5, %11
%13 = tail call i32 @strncpy(i8* %2, i8* %10, i32 %12)
br label %14
14: ; preds = %8, %3
ret void
}