#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 *__findenv(char const *, int, int *);
char *getenv(const char *name) {
  int offset = 0;
  const char *np;
  for (np = name; *np && *np != '='; ++np)
    ;
  return (__findenv(name, (int)(np - name), &offset));
}


x86 assembly (clang, -O0):
<getenv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
je     1150 <getenv+0x40>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3d,%eax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1160 <getenv+0x50>
jmp    1176 <getenv+0x66>
jmp    1165 <getenv+0x55>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    112b <getenv+0x1b>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
lea    -0xc(%rbp),%rdx
call   1030 <__findenv@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getenv>:
push   %rax
movl   $0x0,0x4(%rsp)
xor    %esi,%esi
nopl   0x0(%rax,%rax,1)
movzbl (%rdi,%rsi,1),%eax
test   %al,%al
je     1132 <getenv+0x22>
cmp    $0x3d,%al
je     1132 <getenv+0x22>
add    $0x1,%rsi
jmp    1120 <getenv+0x10>
lea    0x4(%rsp),%rdx
call   1030 <__findenv@plt>
pop    %rcx
ret

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

LLVM IR (-O2):
define i8* @getenv(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 0, i32* %2
br label %4
4: ; preds = %7, %1
%5 = phi i8* [ %0, %1 ], [ %8, %7 ]
%6 = load i8, i8* %5
switch i8 %6, label %7 [
i8 0, label %9
i8 61, label %9
]
7: ; preds = %4
%8 = getelementptr inbounds i8, i8* %5, i64 1
br label %4
9: ; preds = %4, %4
%10 = ptrtoint i8* %5 to i64
%11 = ptrtoint i8* %0 to i64
%12 = sub i64 %10, %11
%13 = trunc i64 %12 to i32
%14 = call i8* @__findenv(i8* %0, i32 %13, i32* %2)
ret i8* %14
}