#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 */
size_t strlen(char const *);
scalar_t__ strncasecmp(char const *, char const *, size_t);
const char *get_value(const char *line, const char *key) {
  size_t linelen = strlen(line);
  size_t keylen = strlen(key);
  if (keylen >= linelen)
    return NULL;
  if (strncasecmp(line, key, keylen))
    return NULL;
  return line + keylen;
}


x86 assembly (clang, -O0):
<get_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jb     1165 <get_value+0x45>
movq   $0x0,-0x8(%rbp)
jmp    1199 <get_value+0x79>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1040 <strncasecmp@plt>
cmp    $0x0,%rax
je     118d <get_value+0x6d>
movq   $0x0,-0x8(%rbp)
jmp    1199 <get_value+0x79>
mov    -0x10(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_value>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <strlen@plt>
mov    %rax,%r12
mov    %r14,%rdi
call   1030 <strlen@plt>
cmp    %r12,%rax
jae    1165 <get_value+0x45>
mov    %rax,%rbx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rax,%rdx
call   1040 <strncasecmp@plt>
mov    %rax,%rcx
add    %rbx,%r15
xor    %eax,%eax
test   %rcx,%rcx
cmove  %r15,%rax
jmp    1167 <get_value+0x47>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @get_value(i8* %0, i8* nocapture %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = icmp ult i64 %4, %3
br i1 %5, label %6, label %11
6: ; preds = %2
%7 = tail call i64 @strncasecmp(i8* %0, i8* %1, i64 %4)
%8 = icmp eq i64 %7, 0
%9 = getelementptr inbounds i8, i8* %0, i64 %4
%10 = select i1 %8, i8* %9, i8* null
br label %11
11: ; preds = %6, %2
%12 = phi i8* [ null, %2 ], [ %10, %6 ]
ret i8* %12
}