#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__ strncmp(char *, char const *, size_t);
size_t remove_env_by_key(const char *key, char **arge) {
  char **arge2;
  size_t keylen;
  keylen = strlen(key);
  for (arge2 = arge; *arge != NULL; ++arge) {
    if (strncmp(*arge, key, keylen) != 0) {
      *(arge2++) = *arge;
    }
  }
  *(arge2++) = NULL;
  return arge - arge2;
}


x86 assembly (clang, -O0):
<remove_env_by_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     11a0 <remove_env_by_key+0x80>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     118a <remove_env_by_key+0x6a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x8,%rdx
mov    %rdx,-0x18(%rbp)
mov    %rcx,(%rax)
jmp    118f <remove_env_by_key+0x6f>
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
jmp    1145 <remove_env_by_key+0x25>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x18(%rbp)
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
sar    $0x3,%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_env_by_key>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
call   1040 <strlen@plt>
mov    (%rbx),%rdi
test   %rdi,%rdi
je     117a <remove_env_by_key+0x5a>
mov    %rax,%r15
mov    %rbx,%r12
jmp    115d <remove_env_by_key+0x3d>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x8(%rbx),%rdi
add    $0x8,%rbx
test   %rdi,%rdi
je     117d <remove_env_by_key+0x5d>
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1150 <remove_env_by_key+0x30>
mov    (%rbx),%rax
mov    %rax,(%r12)
add    $0x8,%r12
jmp    1150 <remove_env_by_key+0x30>
mov    %rbx,%r12
movq   $0x0,(%r12)
sub    %r12,%rbx
add    $0xfffffffffffffff8,%rbx
sar    $0x3,%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @remove_env_by_key(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i8**
%6 = alloca i64
store i8* %0, i8** %3
store i8** %1, i8*** %4
%7 = load i8*, i8** %3
%8 = call i64 @strlen(i8* %7)
store i64 %8, i64* %6
%9 = load i8**, i8*** %4
store i8** %9, i8*** %5
br label %10
10: ; preds = %27, %2
%11 = load i8**, i8*** %4
%12 = load i8*, i8** %11
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %30
14: ; preds = %10
%15 = load i8**, i8*** %4
%16 = load i8*, i8** %15
%17 = load i8*, i8** %3
%18 = load i64, i64* %6
%19 = call i64 @strncmp(i8* %16, i8* %17, i64 %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %14
%22 = load i8**, i8*** %4
%23 = load i8*, i8** %22
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i32 1
store i8** %25, i8*** %5
store i8* %23, i8** %24
br label %26
26: ; preds = %21, %14
br label %27
27: ; preds = %26
%28 = load i8**, i8*** %4
%29 = getelementptr inbounds i8*, i8** %28, i32 1
store i8** %29, i8*** %4
br label %10
30: ; preds = %10
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i32 1
store i8** %32, i8*** %5
store i8* null, i8** %31
%33 = load i8**, i8*** %4
%34 = load i8**, i8*** %5
%35 = ptrtoint i8** %33 to i64
%36 = ptrtoint i8** %34 to i64
%37 = sub i64 %35, %36
%38 = sdiv exact i64 %37, 8
ret i64 %38
}

LLVM IR (-O2):
define i64 @remove_env_by_key(i8* %0, i8** %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = load i8*, i8** %1
%5 = icmp eq i8* %4, null
br i1 %5, label %20, label %6
6: ; preds = %2, %15
%7 = phi i8* [ %18, %15 ], [ %4, %2 ]
%8 = phi i8** [ %17, %15 ], [ %1, %2 ]
%9 = phi i8** [ %16, %15 ], [ %1, %2 ]
%10 = tail call i64 @strncmp(i8* %7, i8* %0, i64 %3)
%11 = icmp eq i64 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %6
%13 = load i8*, i8** %8
%14 = getelementptr inbounds i8*, i8** %9, i64 1
store i8* %13, i8** %9
br label %15
15: ; preds = %6, %12
%16 = phi i8** [ %14, %12 ], [ %9, %6 ]
%17 = getelementptr inbounds i8*, i8** %8, i64 1
%18 = load i8*, i8** %17
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %6
20: ; preds = %15, %2
%21 = phi i8** [ %1, %2 ], [ %16, %15 ]
%22 = phi i8** [ %1, %2 ], [ %17, %15 ]
%23 = getelementptr inbounds i8*, i8** %21, i64 1
store i8* null, i8** %21
%24 = ptrtoint i8** %22 to i64
%25 = ptrtoint i8** %23 to i64
%26 = sub i64 %24, %25
%27 = ashr exact i64 %26, 3
ret i64 %27
}