#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 */
char EOF;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ setenv(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strchr(char *, char);
int strlen(char *);
void pparm_read_env(const char *fname) {
  static char line[2048 + 1];
  FILE *f = NULL;
  if (!(f = fopen(fname, "r"))) {
    fprintf(stderr, "Couldn't open environment %s\n", fname);
    exit(1);
  }
  while (fgets(line, 2048, f)) {
    if (line[strlen(line) - 1] == '\n' || line[strlen(line) - 1] == EOF)
      line[strlen(line) - 1] = 0;
    else {
      fprintf(stderr, "A line is longer than %u\n", 2048);
      exit(1);
    }
    if (line[0] == '#')
      continue;
    char *delim = strchr(line, '=');
    if (!delim)
      continue;
    *delim = 0;
    setenv(line, delim + 1, 0);
  }
  fclose(f);
}


x86 assembly (clang, -O0):
<pparm_read_env>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe61(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11d7 <pparm_read_env+0x57>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe3c(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    11dc <pparm_read_env+0x5c>
mov    -0x10(%rbp),%rdx
lea    0x2e89(%rip),%rdi
mov    $0x800,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     12f4 <pparm_read_env+0x174>
lea    0x2e6e(%rip),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
movslq %eax,%rcx
lea    0x2e5c(%rip),%rax
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
je     1250 <pparm_read_env+0xd0>
lea    0x2e48(%rip),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
movslq %eax,%rcx
lea    0x2e36(%rip),%rax
movsbl (%rax,%rcx,1),%eax
mov    0x2da3(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    1272 <pparm_read_env+0xf2>
lea    0x2e19(%rip),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
movslq %eax,%rcx
lea    0x2e07(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
jmp    1298 <pparm_read_env+0x118>
mov    0x2d5f(%rip),%rax
mov    (%rax),%edi
lea    0xd9e(%rip),%rsi
mov    $0x800,%edx
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
movsbl 0x2dd1(%rip),%eax
cmp    $0x23,%eax
jne    12ad <pparm_read_env+0x12d>
jmp    11dc <pparm_read_env+0x5c>
lea    0x2dbc(%rip),%rdi
mov    $0x3d,%esi
call   1060 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12d2 <pparm_read_env+0x152>
jmp    11dc <pparm_read_env+0x5c>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rsi
add    $0x1,%rsi
lea    0x2d88(%rip),%rdi
xor    %edx,%edx
call   1030 <setenv@plt>
jmp    11dc <pparm_read_env+0x5c>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pparm_read_env>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
lea    0xe71(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     127d <pparm_read_env+0xfd>
mov    %rax,%r14
lea    0x2ec9(%rip),%rbx
mov    %rbx,%rdi
mov    $0x800,%esi
mov    %rax,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     124a <pparm_read_env+0xca>
mov    0x2e21(%rip),%r15
jmp    11e5 <pparm_read_env+0x65>
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    $0x800,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     124a <pparm_read_env+0xca>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%rbx,1)
je     120a <pparm_read_env+0x8a>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
movzbl -0x1(%rax,%rbx,1),%eax
cmp    (%r15),%al
jne    1257 <pparm_read_env+0xd7>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
cmpb   $0x23,0x2e50(%rip)
je     11d0 <pparm_read_env+0x50>
mov    %rbx,%rdi
mov    $0x3d,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     11d0 <pparm_read_env+0x50>
movb   $0x0,(%rax)
add    $0x1,%rax
mov    %rbx,%rdi
mov    %rax,%rsi
xor    %edx,%edx
call   1030 <setenv@plt>
jmp    11d0 <pparm_read_env+0x50>
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <fclose@plt>
mov    0x2d7a(%rip),%rax
mov    (%rax),%edi
lea    0xdb9(%rip),%rsi
mov    $0x800,%edx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x2d54(%rip),%rax
mov    (%rax),%edi
lea    0xd75(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@pparm_read_env.line = internal global [2049 x i8] zeroinitializer
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [30 x i8] c"Couldn't open environment %s\0A\00"
@EOF = global i8 0
@.str.2 = [26 x i8] c"A line is longer than %u\0A\00"
define void @pparm_read_env(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8*
store i8* %0, i8** %2
store i32* null, i32** %3
%5 = load i8*, i8** %2
%6 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %6, i32** %3
%7 = icmp ne i32* %6, null
br i1 %7, label %13, label %8
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %2
%11 = call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %1
br label %14
14: ; preds = %55, %54, %49, %13
%15 = load i32*, i32** %3
%16 = call i64 @fgets(i8* getelementptr inbounds ([2049 x i8], [2049 x i8]* @pparm_read_env.line, i64 0, i64 0), i32 2048, i32* %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %60
18: ; preds = %14
%19 = call i32 @strlen(i8* getelementptr inbounds ([2049 x i8], [2049 x i8]* @pparm_read_env.line, i64 0, i64 0))
%20 = sub nsw i32 %19, 1
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [2049 x i8], [2049 x i8]* @pparm_read_env.line, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 10
br i1 %25, label %36, label %26
26: ; preds = %18
%27 = call i32 @strlen(i8* getelementptr inbounds ([2049 x i8], [2049 x i8]* @pparm_read_env.line, i64 0, i64 0))
%28 = sub nsw i32 %27, 1
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [2049 x i8], [2049 x i8]* @pparm_read_env.line, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = load i8, i8* @EOF
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %32, %34
br i1 %35, label %36, label %41
36: ; preds = %26, %18
%37 = call i32 @strlen(i8* getelementptr inbounds ([2049 x i8], [2049 x i8]* @pparm_read_env.line, i64 0, i64 0))
%38 = sub nsw i32 %37, 1
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [2049 x i8], [2049 x i8]* @pparm_read_env.line, i64 0, i64 %39
store i8 0, i8* %40
br label %45
41: ; preds = %26
%42 = load i32, i32* @stderr
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 2048)
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %36
%46 = load i8, i8* getelementptr inbounds ([2049 x i8], [2049 x i8]* @pparm_read_env.line, i64 0, i64 0)
%47 = sext i8 %46 to i32
%48 = icmp eq i32 %47, 35
br i1 %48, label %49, label %50
49: ; preds = %45
br label %14
50: ; preds = %45
%51 = call i8* @strchr(i8* getelementptr inbounds ([2049 x i8], [2049 x i8]* @pparm_read_env.line, i64 0, i64 0), i8 signext 61)
store i8* %51, i8** %4
%52 = load i8*, i8** %4
%53 = icmp ne i8* %52, null
br i1 %53, label %55, label %54
54: ; preds = %50
br label %14
55: ; preds = %50
%56 = load i8*, i8** %4
store i8 0, i8* %56
%57 = load i8*, i8** %4
%58 = getelementptr inbounds i8, i8* %57, i64 1
%59 = call i32 @setenv(i8* getelementptr inbounds ([2049 x i8], [2049 x i8]* @pparm_read_env.line, i64 0, i64 0), i8* %58, i32 0)
br label %14
60: ; preds = %14
%61 = load i32*, i32** %3
%62 = call i32 @fclose(i32* %61)
ret void
}

LLVM IR (-O2):
@pparm_read_env.line = internal global [2049 x i8] zeroinitializer
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [30 x i8] c"Couldn't open environment %s\0A\00"
@EOF = global i8 0
@.str.2 = [26 x i8] c"A line is longer than %u\0A\00"
define void @pparm_read_env(i8* %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %7, label %4
4: ; preds = %1
%5 = tail call i64 @fgets(i8* getelementptr inbounds ([2049 x i8], [2049 x i8]* @pparm_read_env.line, i64 0, i64 0), i32 2048, i32* %2)
%6 = icmp eq i64 %5, 0
br i1 %6, label %46, label %11
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %4, %33
%12 = tail call i32 @strlen(i8* getelementptr inbounds ([2049 x i8], [2049 x i8]* @pparm_read_env.line, i64 0, i64 0))
%13 = add nsw i32 %12, -1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [2049 x i8], [2049 x i8]* @pparm_read_env.line, i64 0, i64 %14
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 10
br i1 %17, label %26, label %18
18: ; preds = %11
%19 = tail call i32 @strlen(i8* getelementptr inbounds ([2049 x i8], [2049 x i8]* @pparm_read_env.line, i64 0, i64 0))
%20 = add nsw i32 %19, -1
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [2049 x i8], [2049 x i8]* @pparm_read_env.line, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = load i8, i8* @EOF
%25 = icmp eq i8 %23, %24
br i1 %25, label %26, label %36
26: ; preds = %18, %11
%27 = tail call i32 @strlen(i8* getelementptr inbounds ([2049 x i8], [2049 x i8]* @pparm_read_env.line, i64 0, i64 0))
%28 = add nsw i32 %27, -1
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [2049 x i8], [2049 x i8]* @pparm_read_env.line, i64 0, i64 %29
store i8 0, i8* %30
%31 = load i8, i8* getelementptr inbounds ([2049 x i8], [2049 x i8]* @pparm_read_env.line, i64 0, i64 0)
%32 = icmp eq i8 %31, 35
br i1 %32, label %33, label %40
33: ; preds = %43, %40, %26
%34 = tail call i64 @fgets(i8* getelementptr inbounds ([2049 x i8], [2049 x i8]* @pparm_read_env.line, i64 0, i64 0), i32 2048, i32* %2)
%35 = icmp eq i64 %34, 0
br i1 %35, label %46, label %11
36: ; preds = %18
%37 = load i32, i32* @stderr
%38 = tail call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 2048)
%39 = tail call i32 @exit(i32 1)
unreachable
40: ; preds = %26
%41 = tail call i8* @strchr(i8* dereferenceable(1) getelementptr inbounds ([2049 x i8], [2049 x i8]* @pparm_read_env.line, i64 0, i64 0), i8 signext 61)
%42 = icmp eq i8* %41, null
br i1 %42, label %33, label %43
43: ; preds = %40
store i8 0, i8* %41
%44 = getelementptr inbounds i8, i8* %41, i64 1
%45 = tail call i32 @setenv(i8* getelementptr inbounds ([2049 x i8], [2049 x i8]* @pparm_read_env.line, i64 0, i64 0), i8* %44, i32 0)
br label %33
46: ; preds = %33, %4
%47 = tail call i32 @fclose(i32* %2)
ret void
}