#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 after_equal(char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char const *);
scalar_t__ strncmp(char *, char const *, int /*<<< orphan*/);
int /*<<< orphan*/ trim(char *);
int /*<<< orphan*/ write_log(char *, char const *, char *);
int read_buf(char *buf, const char *key, char *value) {
  if (strncmp(buf, key, strlen(key)) == 0) {
    strcpy(value, buf + after_equal(buf));
    trim(value);
    write_log("%s = %s\n", key, value);
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<read_buf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11fa <read_buf+0x9a>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <after_equal@plt>
mov    -0x40(%rbp),%rsi
mov    -0x38(%rbp),%rdi
cltq
add    %rax,%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rdi
call   1070 <trim@plt>
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xe17(%rip),%rdi
call   1080 <write_log@plt>
movl   $0x1,-0x4(%rbp)
jmp    1201 <read_buf+0xa1>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_buf>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    11c2 <read_buf+0x62>
mov    %rbx,%rdi
call   1060 <after_equal@plt>
movslq %eax,%rsi
add    %rbx,%rsi
mov    %r14,%rdi
call   1040 <strcpy@plt>
mov    %r14,%rdi
call   1070 <trim@plt>
lea    0xe4e(%rip),%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1080 <write_log@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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