#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 /*<<< orphan*/ setenv(char const *, char *, int);
char *strchr(char const *, char);
scalar_t__ strlen(char *);
void env_deserialize(const char *env, size_t len) {
  for (;;) {
    char *p = strchr(env, '=');
    if (p == 0 || p - env > len)
      break;
    *p++ = 0;
    setenv(env, p, 1);
    p += strlen(p) + 1;
    len -= (p - env);
    env = p;
  }
  setenv("GATEWAY_INTERFACE", "CGI/1.1", 1);
  setenv("REDIRECT_STATUS", "200", 1);
}


x86 assembly (clang, -O0):
<env_deserialize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x3d,%esi
call   1050 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1172 <env_deserialize+0x42>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
cmp    -0x10(%rbp),%rax
jbe    1177 <env_deserialize+0x47>
jmp    11d3 <env_deserialize+0xa3>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x1,%edx
call   1030 <setenv@plt>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rax
sub    %rax,%rcx
mov    -0x10(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1140 <env_deserialize+0x10>
lea    0xe26(%rip),%rdi
lea    0xe31(%rip),%rsi
mov    $0x1,%edx
call   1030 <setenv@plt>
lea    0xe28(%rip),%rdi
lea    0xe31(%rip),%rsi
mov    $0x1,%edx
call   1030 <setenv@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<env_deserialize>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    $0x3d,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11a1 <env_deserialize+0x71>
mov    %rax,%r15
mov    %r15,%rax
sub    %r14,%rax
cmp    %rbx,%rax
ja     11a1 <env_deserialize+0x71>
lea    0x1(%r15),%r12
movb   $0x0,(%r15)
mov    %r14,%rdi
mov    %r12,%rsi
mov    $0x1,%edx
call   1030 <setenv@plt>
mov    %r12,%rdi
call   1040 <strlen@plt>
lea    (%rax,%r15,1),%r12
add    $0x2,%r12
add    %r14,%rbx
sub    %r12,%rbx
mov    %r12,%rdi
mov    $0x3d,%esi
call   1050 <strchr@plt>
mov    %rax,%r15
mov    %r12,%r14
test   %rax,%rax
jne    1150 <env_deserialize+0x20>
lea    0xe58(%rip),%rdi
lea    0xe63(%rip),%rsi
mov    $0x1,%edx
call   1030 <setenv@plt>
lea    0xe5a(%rip),%rdi
lea    0xe63(%rip),%rsi
mov    $0x1,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <setenv@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"GATEWAY_INTERFACE\00"
@.str.1 = [8 x i8] c"CGI/1.1\00"
@.str.2 = [16 x i8] c"REDIRECT_STATUS\00"
@.str.3 = [4 x i8] c"200\00"
define void @env_deserialize(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
store i8* %0, i8** %3
store i64 %1, i64* %4
br label %6
6: ; preds = %20, %2
%7 = load i8*, i8** %3
%8 = call i8* @strchr(i8* %7, i8 signext 61)
store i8* %8, i8** %5
%9 = load i8*, i8** %5
%10 = icmp eq i8* %9, null
br i1 %10, label %19, label %11
11: ; preds = %6
%12 = load i8*, i8** %5
%13 = load i8*, i8** %3
%14 = ptrtoint i8* %12 to i64
%15 = ptrtoint i8* %13 to i64
%16 = sub i64 %14, %15
%17 = load i64, i64* %4
%18 = icmp ugt i64 %16, %17
br i1 %18, label %19, label %20
19: ; preds = %11, %6
br label %39
20: ; preds = %11
%21 = load i8*, i8** %5
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %5
store i8 0, i8* %21
%23 = load i8*, i8** %3
%24 = load i8*, i8** %5
%25 = call i32 @setenv(i8* %23, i8* %24, i32 1)
%26 = load i8*, i8** %5
%27 = call i64 @strlen(i8* %26)
%28 = add nsw i64 %27, 1
%29 = load i8*, i8** %5
%30 = getelementptr inbounds i8, i8* %29, i64 %28
store i8* %30, i8** %5
%31 = load i8*, i8** %5
%32 = load i8*, i8** %3
%33 = ptrtoint i8* %31 to i64
%34 = ptrtoint i8* %32 to i64
%35 = sub i64 %33, %34
%36 = load i64, i64* %4
%37 = sub i64 %36, %35
store i64 %37, i64* %4
%38 = load i8*, i8** %5
store i8* %38, i8** %3
br label %6
39: ; preds = %19
%40 = call i32 @setenv(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 1)
%41 = call i32 @setenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 1)
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c"GATEWAY_INTERFACE\00"
@.str.1 = [8 x i8] c"CGI/1.1\00"
@.str.2 = [16 x i8] c"REDIRECT_STATUS\00"
@.str.3 = [4 x i8] c"200\00"
define void @env_deserialize(i8* %0, i64 %1) {
%3 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 61)
%4 = icmp eq i8* %3, null
br i1 %4, label %24, label %5
5: ; preds = %2, %13
%6 = phi i8* [ %22, %13 ], [ %3, %2 ]
%7 = phi i64 [ %21, %13 ], [ %1, %2 ]
%8 = phi i8* [ %18, %13 ], [ %0, %2 ]
%9 = ptrtoint i8* %6 to i64
%10 = ptrtoint i8* %8 to i64
%11 = sub i64 %9, %10
%12 = icmp ugt i64 %11, %7
br i1 %12, label %24, label %13
13: ; preds = %5
%14 = getelementptr inbounds i8, i8* %6, i64 1
store i8 0, i8* %6
%15 = tail call i32 @setenv(i8* %8, i8* %14, i32 1)
%16 = tail call i64 @strlen(i8* %14)
%17 = add nsw i64 %16, 1
%18 = getelementptr inbounds i8, i8* %14, i64 %17
%19 = ptrtoint i8* %18 to i64
%20 = add i64 %7, %10
%21 = sub i64 %20, %19
%22 = tail call i8* @strchr(i8* dereferenceable(1) %18, i8 signext 61)
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %5
24: ; preds = %13, %5, %2
%25 = tail call i32 @setenv(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 1)
%26 = tail call i32 @setenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 1)
ret void
}