#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 */
char *strchr(char *, char);
size_t strlen(char const *);
scalar_t__ strncmp(char *, char const *, size_t);
char *env_var_prefix_match(char *env_str, const char *prefix) {
  size_t prefix_len = strlen(prefix);
  if (strncmp(env_str, prefix, prefix_len) == 0) {
    char *match = strchr(env_str + prefix_len, '=');
    if (match != NULL) {
      return match + 1;
    }
  }
  return NULL;
}


x86 assembly (clang, -O0):
<env_var_prefix_match>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    119f <env_var_prefix_match+0x6f>
mov    -0x10(%rbp),%rdi
add    -0x20(%rbp),%rdi
mov    $0x3d,%esi
call   1050 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     119a <env_var_prefix_match+0x6a>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11a7 <env_var_prefix_match+0x77>
jmp    119f <env_var_prefix_match+0x6f>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<env_var_prefix_match>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r15
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %rax,%r14
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1030 <strncmp@plt>
test   %rax,%rax
je     115d <env_var_prefix_match+0x2d>
xor    %eax,%eax
jmp    1176 <env_var_prefix_match+0x46>
add    %r14,%r15
mov    %r15,%rdi
mov    $0x3d,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     1159 <env_var_prefix_match+0x29>
add    $0x1,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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