#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ Putenv(char *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
char *findterm(char *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
char *rmspace(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
char *strchr(char *, char);
int strlen(char *);
int process_Renviron(const char *filename) {
  FILE *fp;
  char *s, *p, sm[255], *lhs, *rhs, msg[2000 + 50];
  int errs = 0;
  if (!filename || !(fp = fopen(filename, "r")))
    return 0;
  snprintf(msg, 2000 + 50, "\n   File %s contains invalid line(s)", filename);
  while (fgets(sm, 255, fp)) {
    sm[255 - 1] = '\0';
    s = rmspace(sm);
    if (strlen(s) == 0 || s[0] == '#')
      continue;
    if (!(p = strchr(s, '='))) {
      errs++;
      if (strlen(msg) < 2000) {
        strcat(msg, "\n      ");
        strcat(msg, s);
      }
      continue;
    }
    *p = '\0';
    lhs = rmspace(s);
    rhs = findterm(rmspace(p + 1));
    if (strlen(lhs) && strlen(rhs))
      Putenv(lhs, rhs);
  }
  fclose(fp);
  if (errs) {
    strcat(msg, "\n   They were ignored\n");
    fprintf(stderr, "%s", msg);
  }
  return 1;
}


x86 assembly (clang, -O0):
<process_Renviron>:
push   %rbp
mov    %rsp,%rbp
sub    $0x960,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x954(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11f2 <process_Renviron+0x42>
mov    -0x10(%rbp),%rdi
lea    0xe21(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11fe <process_Renviron+0x4e>
movl   $0x0,-0x4(%rbp)
jmp    139f <process_Renviron+0x1ef>
lea    -0x950(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x802,%esi
lea    0xded(%rip),%rdx
call   1080 <snprintf@plt>
lea    -0x130(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0xff,%esi
call   10a0 <fgets@plt>
cmp    $0x0,%rax
je     1353 <process_Renviron+0x1a3>
movb   $0x0,-0x32(%rbp)
lea    -0x130(%rbp),%rdi
call   1040 <rmspace@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <strlen@plt>
cmp    $0x0,%eax
je     126f <process_Renviron+0xbf>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
jne    1274 <process_Renviron+0xc4>
jmp    121a <process_Renviron+0x6a>
mov    -0x20(%rbp),%rdi
mov    $0x3d,%esi
call   1070 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    12de <process_Renviron+0x12e>
mov    -0x954(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x954(%rbp)
lea    -0x950(%rbp),%rdi
call   1060 <strlen@plt>
cmp    $0x7d0,%eax
jge    12d9 <process_Renviron+0x129>
lea    -0x950(%rbp),%rdi
lea    0xd63(%rip),%rsi
call   10d0 <strcat@plt>
lea    -0x950(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10d0 <strcat@plt>
jmp    121a <process_Renviron+0x6a>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
call   1040 <rmspace@plt>
mov    %rax,-0x138(%rbp)
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
call   1040 <rmspace@plt>
mov    %rax,%rdi
call   1030 <findterm@plt>
mov    %rax,-0x140(%rbp)
mov    -0x138(%rbp),%rdi
call   1060 <strlen@plt>
cmp    $0x0,%eax
je     134e <process_Renviron+0x19e>
mov    -0x140(%rbp),%rdi
call   1060 <strlen@plt>
cmp    $0x0,%eax
je     134e <process_Renviron+0x19e>
mov    -0x138(%rbp),%rdi
mov    -0x140(%rbp),%rsi
call   1090 <Putenv@plt>
jmp    121a <process_Renviron+0x6a>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
cmpl   $0x0,-0x954(%rbp)
je     1398 <process_Renviron+0x1e8>
lea    -0x950(%rbp),%rdi
lea    0xcb8(%rip),%rsi
call   10d0 <strcat@plt>
mov    0x2c5d(%rip),%rax
mov    (%rax),%edi
lea    -0x950(%rbp),%rdx
lea    0xcb3(%rip),%rsi
call   10b0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x960,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_Renviron>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x908,%rsp
xor    %ebp,%ebp
test   %rdi,%rdi
je     1372 <process_Renviron+0x1c2>
mov    %rdi,%rbx
lea    0xe2a(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     1372 <process_Renviron+0x1c2>
mov    %rax,%r14
lea    0xe14(%rip),%rdx
lea    0x100(%rsp),%rdi
mov    $0x802,%esi
mov    %rbx,%rcx
call   1080 <snprintf@plt>
mov    %rsp,%rdi
mov    $0xff,%esi
mov    %r14,%rdx
call   10a0 <fgets@plt>
test   %rax,%rax
je     1365 <process_Renviron+0x1b5>
xor    %r12d,%r12d
mov    %rsp,%r13
lea    0x100(%rsp),%r15
jmp    1249 <process_Renviron+0x99>
nopl   0x0(%rax)
mov    %r13,%rdi
mov    $0xff,%esi
mov    %r14,%rdx
call   10a0 <fgets@plt>
test   %rax,%rax
je     1327 <process_Renviron+0x177>
movb   $0x0,0xfe(%rsp)
mov    %r13,%rdi
call   1040 <rmspace@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <strlen@plt>
test   %eax,%eax
je     1230 <process_Renviron+0x80>
cmpb   $0x23,(%rbx)
je     1230 <process_Renviron+0x80>
mov    %rbx,%rdi
mov    $0x3d,%esi
call   1070 <strchr@plt>
test   %rax,%rax
je     12d7 <process_Renviron+0x127>
mov    %rax,%rbp
movb   $0x0,(%rax)
mov    %rbx,%rdi
call   1040 <rmspace@plt>
mov    %rax,%rbx
add    $0x1,%rbp
mov    %rbp,%rdi
call   1040 <rmspace@plt>
mov    %rax,%rdi
call   1030 <findterm@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1060 <strlen@plt>
test   %eax,%eax
je     1230 <process_Renviron+0x80>
mov    %rbp,%rdi
call   1060 <strlen@plt>
test   %eax,%eax
je     1230 <process_Renviron+0x80>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1090 <Putenv@plt>
jmp    1230 <process_Renviron+0x80>
mov    %r15,%rdi
call   1060 <strlen@plt>
cmp    $0x7cf,%eax
jg     1300 <process_Renviron+0x150>
mov    %r15,%rdi
lea    0xd37(%rip),%rsi
call   10d0 <strcat@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   10d0 <strcat@plt>
add    $0x1,%r12d
mov    %r13,%rdi
mov    $0xff,%esi
mov    %r14,%rdx
call   10a0 <fgets@plt>
test   %rax,%rax
jne    1249 <process_Renviron+0x99>
mov    %r14,%rdi
call   1050 <fclose@plt>
jmp    1334 <process_Renviron+0x184>
mov    %r14,%rdi
call   1050 <fclose@plt>
test   %r12d,%r12d
je     136d <process_Renviron+0x1bd>
lea    0xcf4(%rip),%rsi
lea    0x100(%rsp),%rbx
mov    %rbx,%rdi
call   10d0 <strcat@plt>
mov    0x2c8e(%rip),%rax
mov    (%rax),%edi
lea    0xceb(%rip),%rsi
mov    %rbx,%rdx
call   10b0 <fprintf@plt>
jmp    136d <process_Renviron+0x1bd>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x908,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [37 x i8] c"\0A File %s contains invalid line(s)\00"
@.str.2 = [8 x i8] c"\0A \00"
@.str.3 = [23 x i8] c"\0A They were ignored\0A\00"
@stderr = global i32 0
@.str.4 = [3 x i8] c"%s\00"
define i32 @process_Renviron(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [255 x i8]
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca [2050 x i8]
%11 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %11
%12 = load i8*, i8** %3
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %18
14: ; preds = %1
%15 = load i8*, i8** %3
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %4
%17 = icmp ne i32* %16, null
br i1 %17, label %19, label %18
18: ; preds = %14, %1
store i32 0, i32* %2
br label %91
19: ; preds = %14
%20 = getelementptr inbounds [2050 x i8], [2050 x i8]* %10, i64 0, i64 0
%21 = load i8*, i8** %3
%22 = call i32 @snprintf(i8* %20, i32 2050, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %21)
br label %23
23: ; preds = %78, %58, %41, %19
%24 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%25 = load i32*, i32** %4
%26 = call i64 @fgets(i8* %24, i32 255, i32* %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %79
28: ; preds = %23
%29 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 254
store i8 0, i8* %29
%30 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%31 = call i8* @rmspace(i8* %30)
store i8* %31, i8** %5
%32 = load i8*, i8** %5
%33 = call i32 @strlen(i8* %32)
%34 = icmp eq i32 %33, 0
br i1 %34, label %41, label %35
35: ; preds = %28
%36 = load i8*, i8** %5
%37 = getelementptr inbounds i8, i8* %36, i64 0
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 35
br i1 %40, label %41, label %42
41: ; preds = %35, %28
br label %23
42: ; preds = %35
%43 = load i8*, i8** %5
%44 = call i8* @strchr(i8* %43, i8 signext 61)
store i8* %44, i8** %6
%45 = icmp ne i8* %44, null
br i1 %45, label %59, label %46
46: ; preds = %42
%47 = load i32, i32* %11
%48 = add nsw i32 %47, 1
store i32 %48, i32* %11
%49 = getelementptr inbounds [2050 x i8], [2050 x i8]* %10, i64 0, i64 0
%50 = call i32 @strlen(i8* %49)
%51 = icmp slt i32 %50, 2000
br i1 %51, label %52, label %58
52: ; preds = %46
%53 = getelementptr inbounds [2050 x i8], [2050 x i8]* %10, i64 0, i64 0
%54 = call i32 @strcat(i8* %53, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%55 = getelementptr inbounds [2050 x i8], [2050 x i8]* %10, i64 0, i64 0
%56 = load i8*, i8** %5
%57 = call i32 @strcat(i8* %55, i8* %56)
br label %58
58: ; preds = %52, %46
br label %23
59: ; preds = %42
%60 = load i8*, i8** %6
store i8 0, i8* %60
%61 = load i8*, i8** %5
%62 = call i8* @rmspace(i8* %61)
store i8* %62, i8** %8
%63 = load i8*, i8** %6
%64 = getelementptr inbounds i8, i8* %63, i64 1
%65 = call i8* @rmspace(i8* %64)
%66 = call i8* @findterm(i8* %65)
store i8* %66, i8** %9
%67 = load i8*, i8** %8
%68 = call i32 @strlen(i8* %67)
%69 = icmp ne i32 %68, 0
br i1 %69, label %70, label %78
70: ; preds = %59
%71 = load i8*, i8** %9
%72 = call i32 @strlen(i8* %71)
%73 = icmp ne i32 %72, 0
br i1 %73, label %74, label %78
74: ; preds = %70
%75 = load i8*, i8** %8
%76 = load i8*, i8** %9
%77 = call i32 @Putenv(i8* %75, i8* %76)
br label %78
78: ; preds = %74, %70, %59
br label %23
79: ; preds = %23
%80 = load i32*, i32** %4
%81 = call i32 @fclose(i32* %80)
%82 = load i32, i32* %11
%83 = icmp ne i32 %82, 0
br i1 %83, label %84, label %90
84: ; preds = %79
%85 = getelementptr inbounds [2050 x i8], [2050 x i8]* %10, i64 0, i64 0
%86 = call i32 @strcat(i8* %85, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%87 = load i32, i32* @stderr
%88 = getelementptr inbounds [2050 x i8], [2050 x i8]* %10, i64 0, i64 0
%89 = call i32 @fprintf(i32 %87, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %88)
br label %90
90: ; preds = %84, %79
store i32 1, i32* %2
br label %91
91: ; preds = %90, %18
%92 = load i32, i32* %2
ret i32 %92
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [37 x i8] c"\0A File %s contains invalid line(s)\00"
@.str.2 = [8 x i8] c"\0A \00"
@.str.3 = [23 x i8] c"\0A They were ignored\0A\00"
@stderr = global i32 0
@.str.4 = [3 x i8] c"%s\00"
define i32 @process_Renviron(i8* %0) {
%2 = alloca [255 x i8]
%3 = alloca [2050 x i8]
%4 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [2050 x i8], [2050 x i8]* %3, i64 0, i64 0
%6 = icmp eq i8* %0, null
br i1 %6, label %64, label %7
7: ; preds = %1
%8 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %64, label %10
10: ; preds = %7
%11 = call i32 @snprintf(i8* %5, i32 2050, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%12 = call i64 @fgets(i8* %4, i32 255, i32* %8)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = call i32 @fclose(i32* %8)
br label %64
16: ; preds = %10
%17 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 254
br label %18
18: ; preds = %16, %40
%19 = phi i32 [ 0, %16 ], [ %34, %40 ]
br label %20
20: ; preds = %18, %27
store i8 0, i8* %17
%21 = call i8* @rmspace(i8* %4)
%22 = call i32 @strlen(i8* %21)
%23 = icmp eq i32 %22, 0
br i1 %23, label %27, label %24
24: ; preds = %20
%25 = load i8, i8* %21
%26 = icmp eq i8 %25, 35
br i1 %26, label %27, label %30
27: ; preds = %45, %52, %55, %20, %24
%28 = call i64 @fgets(i8* %4, i32 255, i32* %8)
%29 = icmp eq i64 %28, 0
br i1 %29, label %57, label %20
30: ; preds = %24
%31 = call i8* @strchr(i8* %21, i8 signext 61)
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %45
33: ; preds = %30
%34 = add nuw nsw i32 %19, 1
%35 = call i32 @strlen(i8* %5)
%36 = icmp slt i32 %35, 2000
br i1 %36, label %37, label %40
37: ; preds = %33
%38 = call i32 @strcat(i8* %5, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%39 = call i32 @strcat(i8* %5, i8* %21)
br label %40
40: ; preds = %37, %33
%41 = call i64 @fgets(i8* %4, i32 255, i32* %8)
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %18
43: ; preds = %40
%44 = call i32 @fclose(i32* %8)
br label %60
45: ; preds = %30
store i8 0, i8* %31
%46 = call i8* @rmspace(i8* %21)
%47 = getelementptr inbounds i8, i8* %31, i64 1
%48 = call i8* @rmspace(i8* %47)
%49 = call i8* @findterm(i8* %48)
%50 = call i32 @strlen(i8* %46)
%51 = icmp eq i32 %50, 0
br i1 %51, label %27, label %52
52: ; preds = %45
%53 = call i32 @strlen(i8* %49)
%54 = icmp eq i32 %53, 0
br i1 %54, label %27, label %55
55: ; preds = %52
%56 = call i32 @Putenv(i8* %46, i8* %49)
br label %27
57: ; preds = %27
%58 = call i32 @fclose(i32* %8)
%59 = icmp eq i32 %19, 0
br i1 %59, label %64, label %60
60: ; preds = %43, %57
%61 = call i32 @strcat(i8* %5, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%62 = load i32, i32* @stderr
%63 = call i32 @fprintf(i32 %62, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %5)
br label %64
64: ; preds = %14, %57, %60, %1, %7
%65 = phi i32 [ 0, %7 ], [ 0, %1 ], [ 1, %60 ], [ 1, %57 ], [ 1, %14 ]
ret i32 %65
}