#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 */
struct stat {
  scalar_t__ st_size;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
char *MAP_FAILED;
int /*<<< orphan*/ MAP_PRIVATE;
int O_CLOEXEC;
int O_RDONLY;
int /*<<< orphan*/ PROT_READ;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
scalar_t__ fstat(int, struct stat *);
scalar_t__ isspace(char);
char *mmap(int /*<<< orphan*/ *, size_t, int /*<<< orphan*/, int /*<<< orphan*/,
           int, int /*<<< orphan*/);
int /*<<< orphan*/ munmap(char *, size_t);
int open(char const *, int);
int /*<<< orphan*/ *open_memstream(char **, size_t *);
int /*<<< orphan*/ setenv(char *, char *, int);
int /*<<< orphan*/ stderr;
char *strndup(char *, size_t);
void set_environ(const char *fname) {
  char *a, *map = NULL;
  int fd = -1;
  struct stat sb;
  if ((fd = open(fname, O_RDONLY | O_CLOEXEC)) < 0) {
    fprintf(stderr, "ERROR: open: %s: %m\n", fname);
    exit(1);
  }
  if (fstat(fd, &sb) < 0) {
    fprintf(stderr, "ERROR: fstat: %s: %m\n", fname);
    exit(1);
  }
  if (!sb.st_size) {
    close(fd);
    return;
  }
  if ((a = map = mmap(NULL, (size_t)sb.st_size, PROT_READ, MAP_PRIVATE, fd,
                      0)) == MAP_FAILED) {
    fprintf(stderr, "ERROR: mmap: %s: %m\n", fname);
    exit(1);
  }
  while (a && *a) {
    char *name, *value;
    size_t namesz, valuesz;
    FILE *valfd;
    int is_quote = 0;
    while (isspace(*a))
      a++;
    if (*a == '\0')
      break;
    namesz = valuesz = 0;
    while (a[namesz] != '=') {
      if (a[namesz] == '\0') {
        fprintf(
            stderr,
            "ERROR: open: %s: expect '=' character for '%s', but found EOF\n",
            fname, a);
        exit(1);
      }
      namesz++;
    }
    name = strndup(a, namesz);
    a += namesz + 1;
    if (*a != '"') {
      fprintf(stderr,
              "ERROR: open: %s: expect opening quote not found for '%s', but "
              "'%c' found\n",
              fname, name, *a);
      exit(1);
    }
    a++;
    if ((valfd = open_memstream(&value, &valuesz)) == NULL) {
      fprintf(stderr, "ERROR: open_memstream: %m\n");
      exit(1);
    }
    while (*a != '\0') {
      if (!is_quote) {
        if (*a == '"')
          break;
        if (*a == '\\') {
          is_quote = 1;
          a++;
          continue;
        }
      } else {
        is_quote = 0;
      }
      fprintf(valfd, "%c", *a);
      a++;
    }
    fclose(valfd);
    if (*a != '"') {
      fprintf(stderr,
              "ERROR: open: %s: expect closing quote not found for '%s', but "
              "'%c' found\n",
              fname, name, *a);
      exit(1);
    }
    a++;
    setenv(name, value, 1);
    free(name);
    free(value);
  }
  munmap(map, (size_t)sb.st_size);
  close(fd);
}


x86 assembly (clang, -O0):
<set_environ>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2dea(%rip),%rax
mov    (%rax),%esi
mov    0x2db1(%rip),%rax
or     (%rax),%esi
call   10d0 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    1237 <set_environ+0x67>
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xdda(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x1c(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   10f0 <fstat@plt>
cmp    $0x0,%rax
jge    1272 <set_environ+0xa2>
mov    0x2d7c(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xdb4(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
cmpq   $0x0,-0x28(%rbp)
jne    128a <set_environ+0xba>
mov    -0x1c(%rbp),%edi
call   1080 <close@plt>
jmp    15ab <set_environ+0x3db>
mov    -0x28(%rbp),%rsi
mov    0x2d63(%rip),%rax
mov    (%rax),%edx
mov    0x2d2a(%rip),%rax
mov    (%rax),%ecx
mov    -0x1c(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1070 <mmap@plt>
mov    %rax,-0x18(%rbp)
mov    %rax,-0x10(%rbp)
mov    0x2d01(%rip),%rcx
cmp    (%rcx),%rax
jne    12ed <set_environ+0x11d>
mov    0x2d01(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xd4f(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
jmp    12f2 <set_environ+0x122>
xor    %eax,%eax
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x55(%rbp)
je     1312 <set_environ+0x142>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x55(%rbp)
mov    -0x55(%rbp),%al
test   $0x1,%al
jne    1322 <set_environ+0x152>
jmp    1596 <set_environ+0x3c6>
movl   $0x0,-0x54(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1090 <isspace@plt>
cmp    $0x0,%rax
je     1350 <set_environ+0x180>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1329 <set_environ+0x159>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1365 <set_environ+0x195>
jmp    1596 <set_environ+0x3c6>
movq   $0x0,-0x48(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x40(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3d,%eax
je     13d9 <set_environ+0x209>
mov    -0x10(%rbp),%rax
mov    -0x40(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    13c8 <set_environ+0x1f8>
mov    0x2c2a(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xc89(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    1375 <set_environ+0x1a5>
mov    -0x10(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   10a0 <strndup@plt>
mov    %rax,-0x30(%rbp)
mov    -0x40(%rbp),%rax
add    $0x1,%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x22,%eax
je     143b <set_environ+0x26b>
mov    0x2bbf(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x10(%rbp),%rax
movsbl (%rax),%r8d
lea    0xc55(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
lea    -0x38(%rbp),%rdi
lea    -0x48(%rbp),%rsi
call   1040 <open_memstream@plt>
mov    %rax,-0x50(%rbp)
cmp    $0x0,%rax
jne    1483 <set_environ+0x2b3>
mov    0x2b67(%rip),%rax
mov    (%rax),%edi
lea    0xc57(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
jmp    1488 <set_environ+0x2b8>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1517 <set_environ+0x347>
cmpl   $0x0,-0x54(%rbp)
jne    14e4 <set_environ+0x314>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x22,%eax
jne    14b7 <set_environ+0x2e7>
jmp    1517 <set_environ+0x347>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
jne    14df <set_environ+0x30f>
movl   $0x1,-0x54(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1488 <set_environ+0x2b8>
jmp    14eb <set_environ+0x31b>
movl   $0x0,-0x54(%rbp)
mov    -0x50(%rbp),%rax
mov    %eax,%edi
mov    -0x10(%rbp),%rax
movsbl (%rax),%edx
lea    0xbe5(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1488 <set_environ+0x2b8>
mov    -0x50(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x22,%eax
je     1561 <set_environ+0x391>
mov    0x2a99(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x10(%rbp),%rax
movsbl (%rax),%r8d
lea    0xb97(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    $0x1,%edx
call   1050 <setenv@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
jmp    12f2 <set_environ+0x122>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   10c0 <munmap@plt>
mov    -0x1c(%rbp),%edi
call   1080 <close@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_environ>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%rbx
mov    0x2df8(%rip),%rax
mov    0x2dc1(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   10d0 <open@plt>
test   %eax,%eax
js     1465 <set_environ+0x295>
mov    %eax,%ebp
lea    0x20(%rsp),%rsi
mov    %eax,%edi
call   10f0 <fstat@plt>
test   %rax,%rax
js     1477 <set_environ+0x2a7>
mov    0x20(%rsp),%rsi
test   %rsi,%rsi
je     13cd <set_environ+0x1fd>
mov    %rbx,(%rsp)
mov    0x2dc8(%rip),%rax
mov    (%rax),%edx
mov    0x2d8f(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %rsi,0x10(%rsp)
mov    %ebp,%r8d
xor    %r9d,%r9d
call   1070 <mmap@plt>
mov    %rax,%r13
mov    0x2d69(%rip),%rax
cmp    (%rax),%r13
je     148c <set_environ+0x2bc>
test   %r13,%r13
je     13aa <set_environ+0x1da>
mov    0x0(%r13),%al
test   %al,%al
je     13aa <set_environ+0x1da>
lea    0xe68(%rip),%r14
mov    %r13,%rbx
nop
movsbl %al,%edi
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
call   1090 <isspace@plt>
test   %rax,%rax
je     12b0 <set_environ+0xe0>
movsbl 0x1(%rbx),%edi
add    $0x1,%rbx
jmp    1290 <set_environ+0xc0>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmpb   $0x0,(%rbx)
je     13aa <set_environ+0x1da>
movq   $0x0,0x18(%rsp)
lea    0x2(%rbx),%r15
xor    %esi,%esi
nopl   0x0(%rax,%rax,1)
movzbl -0x2(%r15),%eax
cmp    $0x3d,%al
je     12f0 <set_environ+0x120>
test   %al,%al
je     13e2 <set_environ+0x212>
add    $0x1,%rsi
add    $0x1,%r15
jmp    12d0 <set_environ+0x100>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   10a0 <strndup@plt>
mov    %rax,%r12
movsbl -0x1(%r15),%r8d
cmp    $0x22,%r8d
jne    140a <set_environ+0x23a>
lea    0x8(%rsp),%rdi
lea    0x18(%rsp),%rsi
call   1040 <open_memstream@plt>
test   %rax,%rax
je     141c <set_environ+0x24c>
mov    %rax,%rbx
mov    (%r15),%al
test   %al,%al
je     1360 <set_environ+0x190>
mov    $0x1,%cl
jmp    1352 <set_environ+0x182>
cmp    $0x22,%al
je     1360 <set_environ+0x190>
movsbl %al,%edx
mov    %ebx,%edi
mov    %r14,%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    $0x1,%cl
movzbl 0x1(%r15),%eax
add    $0x1,%r15
test   %al,%al
je     1360 <set_environ+0x190>
test   $0x1,%cl
je     1334 <set_environ+0x164>
cmp    $0x5c,%al
jne    1330 <set_environ+0x160>
xor    %ecx,%ecx
jmp    1345 <set_environ+0x175>
nop
mov    %rbx,%rdi
call   1060 <fclose@plt>
movsbl (%r15),%r8d
cmp    $0x22,%r8d
jne    143d <set_environ+0x26d>
lea    0x1(%r15),%rbx
mov    0x8(%rsp),%rsi
mov    %r12,%rdi
mov    $0x1,%edx
call   1050 <setenv@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    0x1(%r15),%al
test   %al,%al
jne    1280 <set_environ+0xb0>
mov    %r13,%rdi
mov    0x10(%rsp),%rsi
call   10c0 <munmap@plt>
mov    %ebp,%edi
call   1080 <close@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %ebp,%edi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <close@plt>
mov    0x2be7(%rip),%rax
mov    (%rax),%edi
lea    0xc4e(%rip),%rsi
mov    (%rsp),%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    0x2bbf(%rip),%rax
mov    (%rax),%edi
lea    0xc65(%rip),%rsi
jmp    144d <set_environ+0x27d>
mov    0x2bad(%rip),%rax
mov    (%rax),%edi
lea    0xc9d(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    0x2b8c(%rip),%rax
mov    (%rax),%edi
lea    0xc9a(%rip),%rsi
mov    (%rsp),%rdx
mov    %r12,%rcx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    0x2b64(%rip),%rax
mov    (%rax),%edi
lea    0xb8b(%rip),%rsi
jmp    1487 <set_environ+0x2b7>
mov    0x2b52(%rip),%rax
mov    (%rax),%edi
lea    0xb8e(%rip),%rsi
mov    %rbx,%rdx
jmp    14a0 <set_environ+0x2d0>
mov    0x2b3d(%rip),%rax
mov    (%rax),%edi
lea    0xb8f(%rip),%rsi
mov    (%rsp),%rdx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i64 }
@O_RDONLY = global i32 0
@O_CLOEXEC = global i32 0
@stderr = global i32 0
@.str = [21 x i8] c"ERROR: open: %s: %m\0A\00"
@.str.1 = [22 x i8] c"ERROR: fstat: %s: %m\0A\00"
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_FAILED = global i8* null
@.str.2 = [21 x i8] c"ERROR: mmap: %s: %m\0A\00"
@.str.3 = [63 x i8] c"ERROR: open: %s: expect '=' character for '%s', but found EOF\0A\00"
@.str.4 = [74 x i8] c"ERROR: open: %s: expect opening quote not found for '%s', but '%c' found\0A\00"
@.str.5 = [27 x i8] c"ERROR: open_memstream: %m\0A\00"
@.str.6 = [3 x i8] c"%c\00"
@.str.7 = [74 x i8] c"ERROR: open: %s: expect closing quote not found for '%s', but '%c' found\0A\00"
define void @set_environ(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca %struct.stat
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i32*
%12 = alloca i32
store i8* %0, i8** %2
store i8* null, i8** %4
store i32 -1, i32* %5
%13 = load i8*, i8** %2
%14 = load i32, i32* @O_RDONLY
%15 = load i32, i32* @O_CLOEXEC
%16 = or i32 %14, %15
%17 = call i32 @open(i8* %13, i32 %16)
store i32 %17, i32* %5
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %1
%20 = load i32, i32* @stderr
%21 = load i8*, i8** %2
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %1
%25 = load i32, i32* %5
%26 = call i64 @fstat(i32 %25, %struct.stat* %6)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %24
%29 = load i32, i32* @stderr
%30 = load i8*, i8** %2
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %30)
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %24
%34 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%35 = load i64, i64* %34
%36 = icmp ne i64 %35, 0
br i1 %36, label %40, label %37
37: ; preds = %33
%38 = load i32, i32* %5
%39 = call i32 @close(i32 %38)
br label %201
40: ; preds = %33
%41 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%42 = load i64, i64* %41
%43 = load i32, i32* @PROT_READ
%44 = load i32, i32* @MAP_PRIVATE
%45 = load i32, i32* %5
%46 = call i8* @mmap(i32* null, i64 %42, i32 %43, i32 %44, i32 %45, i32 0)
store i8* %46, i8** %4
store i8* %46, i8** %3
%47 = load i8*, i8** @MAP_FAILED
%48 = icmp eq i8* %46, %47
br i1 %48, label %49, label %54
49: ; preds = %40
%50 = load i32, i32* @stderr
%51 = load i8*, i8** %2
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %51)
%53 = call i32 @exit(i32 1)
unreachable
54: ; preds = %40
br label %55
55: ; preds = %184, %54
%56 = load i8*, i8** %3
%57 = icmp ne i8* %56, null
br i1 %57, label %58, label %63
58: ; preds = %55
%59 = load i8*, i8** %3
%60 = load i8, i8* %59
%61 = sext i8 %60 to i32
%62 = icmp ne i32 %61, 0
br label %63
63: ; preds = %58, %55
%64 = phi i1 [ false, %55 ], [ %62, %58 ]
br i1 %64, label %65, label %194
65: ; preds = %63
store i32 0, i32* %12
br label %66
66: ; preds = %71, %65
%67 = load i8*, i8** %3
%68 = load i8, i8* %67
%69 = call i64 @isspace(i8 signext %68)
%70 = icmp ne i64 %69, 0
br i1 %70, label %71, label %74
71: ; preds = %66
%72 = load i8*, i8** %3
%73 = getelementptr inbounds i8, i8* %72, i32 1
store i8* %73, i8** %3
br label %66
74: ; preds = %66
%75 = load i8*, i8** %3
%76 = load i8, i8* %75
%77 = sext i8 %76 to i32
%78 = icmp eq i32 %77, 0
br i1 %78, label %79, label %80
79: ; preds = %74
br label %194
80: ; preds = %74
store i64 0, i64* %10
store i64 0, i64* %9
br label %81
81: ; preds = %101, %80
%82 = load i8*, i8** %3
%83 = load i64, i64* %9
%84 = getelementptr inbounds i8, i8* %82, i64 %83
%85 = load i8, i8* %84
%86 = sext i8 %85 to i32
%87 = icmp ne i32 %86, 61
br i1 %87, label %88, label %104
88: ; preds = %81
%89 = load i8*, i8** %3
%90 = load i64, i64* %9
%91 = getelementptr inbounds i8, i8* %89, i64 %90
%92 = load i8, i8* %91
%93 = sext i8 %92 to i32
%94 = icmp eq i32 %93, 0
br i1 %94, label %95, label %101
95: ; preds = %88
%96 = load i32, i32* @stderr
%97 = load i8*, i8** %2
%98 = load i8*, i8** %3
%99 = call i32 (i32, i8*, ...) @fprintf(i32 %96, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.3, i64 0, i64 0), i8* %97, i8* %98)
%100 = call i32 @exit(i32 1)
unreachable
101: ; preds = %88
%102 = load i64, i64* %9
%103 = add i64 %102, 1
store i64 %103, i64* %9
br label %81
104: ; preds = %81
%105 = load i8*, i8** %3
%106 = load i64, i64* %9
%107 = call i8* @strndup(i8* %105, i64 %106)
store i8* %107, i8** %7
%108 = load i64, i64* %9
%109 = add i64 %108, 1
%110 = load i8*, i8** %3
%111 = getelementptr inbounds i8, i8* %110, i64 %109
store i8* %111, i8** %3
%112 = load i8*, i8** %3
%113 = load i8, i8* %112
%114 = sext i8 %113 to i32
%115 = icmp ne i32 %114, 34
br i1 %115, label %116, label %125
116: ; preds = %104
%117 = load i32, i32* @stderr
%118 = load i8*, i8** %2
%119 = load i8*, i8** %7
%120 = load i8*, i8** %3
%121 = load i8, i8* %120
%122 = sext i8 %121 to i32
%123 = call i32 (i32, i8*, ...) @fprintf(i32 %117, i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.4, i64 0, i64 0), i8* %118, i8* %119, i32 %122)
%124 = call i32 @exit(i32 1)
unreachable
125: ; preds = %104
%126 = load i8*, i8** %3
%127 = getelementptr inbounds i8, i8* %126, i32 1
store i8* %127, i8** %3
%128 = call i32* @open_memstream(i8** %8, i64* %10)
store i32* %128, i32** %11
%129 = icmp eq i32* %128, null
br i1 %129, label %130, label %134
130: ; preds = %125
%131 = load i32, i32* @stderr
%132 = call i32 (i32, i8*, ...) @fprintf(i32 %131, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
%133 = call i32 @exit(i32 1)
unreachable
134: ; preds = %125
br label %135
135: ; preds = %159, %154, %134
%136 = load i8*, i8** %3
%137 = load i8, i8* %136
%138 = sext i8 %137 to i32
%139 = icmp ne i32 %138, 0
br i1 %139, label %140, label %168
140: ; preds = %135
%141 = load i32, i32* %12
%142 = icmp ne i32 %141, 0
br i1 %142, label %158, label %143
143: ; preds = %140
%144 = load i8*, i8** %3
%145 = load i8, i8* %144
%146 = sext i8 %145 to i32
%147 = icmp eq i32 %146, 34
br i1 %147, label %148, label %149
148: ; preds = %143
br label %168
149: ; preds = %143
%150 = load i8*, i8** %3
%151 = load i8, i8* %150
%152 = sext i8 %151 to i32
%153 = icmp eq i32 %152, 92
br i1 %153, label %154, label %157
154: ; preds = %149
store i32 1, i32* %12
%155 = load i8*, i8** %3
%156 = getelementptr inbounds i8, i8* %155, i32 1
store i8* %156, i8** %3
br label %135
157: ; preds = %149
br label %159
158: ; preds = %140
store i32 0, i32* %12
br label %159
159: ; preds = %158, %157
%160 = load i32*, i32** %11
%161 = ptrtoint i32* %160 to i32
%162 = load i8*, i8** %3
%163 = load i8, i8* %162
%164 = sext i8 %163 to i32
%165 = call i32 (i32, i8*, ...) @fprintf(i32 %161, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %164)
%166 = load i8*, i8** %3
%167 = getelementptr inbounds i8, i8* %166, i32 1
store i8* %167, i8** %3
br label %135
168: ; preds = %148, %135
%169 = load i32*, i32** %11
%170 = call i32 @fclose(i32* %169)
%171 = load i8*, i8** %3
%172 = load i8, i8* %171
%173 = sext i8 %172 to i32
%174 = icmp ne i32 %173, 34
br i1 %174, label %175, label %184
175: ; preds = %168
%176 = load i32, i32* @stderr
%177 = load i8*, i8** %2
%178 = load i8*, i8** %7
%179 = load i8*, i8** %3
%180 = load i8, i8* %179
%181 = sext i8 %180 to i32
%182 = call i32 (i32, i8*, ...) @fprintf(i32 %176, i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.7, i64 0, i64 0), i8* %177, i8* %178, i32 %181)
%183 = call i32 @exit(i32 1)
unreachable
184: ; preds = %168
%185 = load i8*, i8** %3
%186 = getelementptr inbounds i8, i8* %185, i32 1
store i8* %186, i8** %3
%187 = load i8*, i8** %7
%188 = load i8*, i8** %8
%189 = call i32 @setenv(i8* %187, i8* %188, i32 1)
%190 = load i8*, i8** %7
%191 = call i32 @free(i8* %190)
%192 = load i8*, i8** %8
%193 = call i32 @free(i8* %192)
br label %55
194: ; preds = %79, %63
%195 = load i8*, i8** %4
%196 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%197 = load i64, i64* %196
%198 = call i32 @munmap(i8* %195, i64 %197)
%199 = load i32, i32* %5
%200 = call i32 @close(i32 %199)
br label %201
201: ; preds = %194, %37
ret void
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@O_RDONLY = global i32 0
@O_CLOEXEC = global i32 0
@stderr = global i32 0
@.str = [21 x i8] c"ERROR: open: %s: %m\0A\00"
@.str.1 = [22 x i8] c"ERROR: fstat: %s: %m\0A\00"
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_FAILED = global i8* null
@.str.2 = [21 x i8] c"ERROR: mmap: %s: %m\0A\00"
@.str.3 = [63 x i8] c"ERROR: open: %s: expect '=' character for '%s', but found EOF\0A\00"
@.str.4 = [74 x i8] c"ERROR: open: %s: expect opening quote not found for '%s', but '%c' found\0A\00"
@.str.5 = [27 x i8] c"ERROR: open_memstream: %m\0A\00"
@.str.6 = [3 x i8] c"%c\00"
@.str.7 = [74 x i8] c"ERROR: open: %s: expect closing quote not found for '%s', but '%c' found\0A\00"
define void @set_environ(i8* %0) {
%2 = alloca %struct.stat
%3 = alloca i8*
%4 = alloca i64
%5 = bitcast %struct.stat* %2 to i8*
%6 = load i32, i32* @O_RDONLY
%7 = load i32, i32* @O_CLOEXEC
%8 = or i32 %7, %6
%9 = tail call i32 @open(i8* %0, i32 %8)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %0)
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %1
%16 = call i64 @fstat(i32 %9, %struct.stat* %2)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %15
%19 = load i32, i32* @stderr
%20 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %15
%23 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%24 = load i64, i64* %23
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = tail call i32 @close(i32 %9)
br label %132
28: ; preds = %22
%29 = load i32, i32* @PROT_READ
%30 = load i32, i32* @MAP_PRIVATE
%31 = tail call i8* @mmap(i32* null, i64 %24, i32 %29, i32 %30, i32 %9, i32 0)
%32 = load i8*, i8** @MAP_FAILED
%33 = icmp eq i8* %31, %32
br i1 %33, label %41, label %34
34: ; preds = %28
%35 = icmp eq i8* %31, null
br i1 %35, label %129, label %36
36: ; preds = %34
%37 = bitcast i8** %3 to i8*
%38 = bitcast i64* %4 to i8*
%39 = load i8, i8* %31
%40 = icmp eq i8 %39, 0
br i1 %40, label %129, label %45
41: ; preds = %28
%42 = load i32, i32* @stderr
%43 = tail call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%44 = tail call i32 @exit(i32 1)
unreachable
45: ; preds = %36, %120
%46 = phi i8 [ %127, %120 ], [ %39, %36 ]
%47 = phi i8* [ %121, %120 ], [ %31, %36 ]
%48 = call i64 @isspace(i8 signext %46)
%49 = icmp eq i64 %48, 0
br i1 %49, label %56, label %50
50: ; preds = %45, %50
%51 = phi i8* [ %52, %50 ], [ %47, %45 ]
%52 = getelementptr inbounds i8, i8* %51, i64 1
%53 = load i8, i8* %52
%54 = call i64 @isspace(i8 signext %53)
%55 = icmp eq i64 %54, 0
br i1 %55, label %56, label %50
56: ; preds = %50, %45
%57 = phi i8* [ %47, %45 ], [ %52, %50 ]
%58 = load i8, i8* %57
%59 = icmp eq i8 %58, 0
br i1 %59, label %60, label %61
60: ; preds = %56
br label %129
61: ; preds = %56
store i64 0, i64* %4
br label %62
62: ; preds = %70, %61
%63 = phi i64 [ 0, %61 ], [ %71, %70 ]
%64 = getelementptr inbounds i8, i8* %57, i64 %63
%65 = load i8, i8* %64
switch i8 %65, label %70 [
i8 61, label %72
i8 0, label %66
]
66: ; preds = %62
%67 = load i32, i32* @stderr
%68 = call i32 (i32, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.3, i64 0, i64 0), i8* %0, i8* %57)
%69 = call i32 @exit(i32 1)
unreachable
70: ; preds = %62
%71 = add i64 %63, 1
br label %62
72: ; preds = %62
%73 = call i8* @strndup(i8* %57, i64 %63)
%74 = add i64 %63, 1
%75 = getelementptr inbounds i8, i8* %57, i64 %74
%76 = load i8, i8* %75
%77 = icmp eq i8 %76, 34
br i1 %77, label %83, label %78
78: ; preds = %72
%79 = sext i8 %76 to i32
%80 = load i32, i32* @stderr
%81 = call i32 (i32, i8*, ...) @fprintf(i32 %80, i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.4, i64 0, i64 0), i8* %0, i8* %73, i32 %79)
%82 = call i32 @exit(i32 1)
unreachable
83: ; preds = %72
%84 = getelementptr inbounds i8, i8* %75, i64 1
%85 = call i32* @open_memstream(i8** %3, i64* %4)
%86 = icmp eq i32* %85, null
br i1 %86, label %93, label %87
87: ; preds = %83
%88 = load i8, i8* %84
%89 = icmp eq i8 %88, 0
br i1 %89, label %110, label %90
90: ; preds = %87
%91 = ptrtoint i32* %85 to i64
%92 = trunc i64 %91 to i32
br label %97
93: ; preds = %83
%94 = load i32, i32* @stderr
%95 = call i32 (i32, i8*, ...) @fprintf(i32 %94, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
%96 = call i32 @exit(i32 1)
unreachable
97: ; preds = %90, %102
%98 = phi i8 [ %88, %90 ], [ %105, %102 ]
%99 = phi i1 [ true, %90 ], [ %103, %102 ]
%100 = phi i8* [ %84, %90 ], [ %104, %102 ]
br i1 %99, label %101, label %107
101: ; preds = %97
switch i8 %98, label %107 [
i8 34, label %110
i8 92, label %102
]
102: ; preds = %101, %107
%103 = phi i1 [ true, %107 ], [ false, %101 ]
%104 = getelementptr inbounds i8, i8* %100, i64 1
%105 = load i8, i8* %104
%106 = icmp eq i8 %105, 0
br i1 %106, label %110, label %97
107: ; preds = %97, %101
%108 = sext i8 %98 to i32
%109 = call i32 (i32, i8*, ...) @fprintf(i32 %92, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %108)
br label %102
110: ; preds = %102, %101, %87
%111 = phi i8* [ %84, %87 ], [ %100, %101 ], [ %104, %102 ]
%112 = call i32 @fclose(i32* %85)
%113 = load i8, i8* %111
%114 = icmp eq i8 %113, 34
br i1 %114, label %120, label %115
115: ; preds = %110
%116 = sext i8 %113 to i32
%117 = load i32, i32* @stderr
%118 = call i32 (i32, i8*, ...) @fprintf(i32 %117, i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.7, i64 0, i64 0), i8* %0, i8* %73, i32 %116)
%119 = call i32 @exit(i32 1)
unreachable
120: ; preds = %110
%121 = getelementptr inbounds i8, i8* %111, i64 1
%122 = load i8*, i8** %3
%123 = call i32 @setenv(i8* %73, i8* %122, i32 1)
%124 = call i32 @free(i8* %73)
%125 = load i8*, i8** %3
%126 = call i32 @free(i8* %125)
%127 = load i8, i8* %121
%128 = icmp eq i8 %127, 0
br i1 %128, label %129, label %45
129: ; preds = %120, %36, %34, %60
%130 = call i32 @munmap(i8* %31, i64 %24)
%131 = call i32 @close(i32 %9)
br label %132
132: ; preds = %129, %26
ret void
}