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

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int fw_setenv(int, char **);
int stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
char *strtok(char *, char *);
int sete(int argc, char **argv) {
  struct stat st;
  if (stat(argv[1], &st) == -1) {
    return (fw_setenv(argc, argv));
  } else {
    char *fname = argv[1];
    int c = 1;
    char *v[3];
    FILE *fp;
    int rc;
    char dump[512];
    char *VAR;
    char *VAL;
    char *SE;
    fp = fopen(fname, "r");
    if (fp == NULL) {
      fprintf(stderr, "Cannot read setenv file %s: %s\n", fname,
              strerror(errno));
      return (1);
    }
    while (fgets(dump, sizeof(dump), fp)) {
      if (dump[0] == '#')
        continue;
      if (dump[0] == '\n')
        continue;
      c = 0;
      SE = strtok(dump, " ");
      v[c++] = SE;
      VAR = strtok(NULL, " \n");
      v[c++] = VAR;
      VAL = strtok(NULL, "\n");
      if (VAL)
        v[c++] = VAL;
      rc = fw_setenv(c, v);
      if (rc)
        return (1);
    }
    fclose(fp);
    return (0);
  }
}


x86 assembly (clang, -O0):
<sete>:
push   %rbp
mov    %rsp,%rbp
sub    $0x280,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
call   1070 <stat@plt>
cmp    $0xffffffff,%eax
jne    11c0 <sete+0x40>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <fw_setenv@plt>
mov    %eax,-0x4(%rbp)
jmp    1372 <sete+0x1f2>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe22(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    1242 <sete+0xc2>
mov    0x2de7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x274(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x270(%rbp)
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x274(%rbp),%edi
mov    -0x270(%rbp),%rdx
mov    %rax,%rcx
lea    0xdd1(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1372 <sete+0x1f2>
jmp    1247 <sete+0xc7>
lea    -0x250(%rbp),%rdi
mov    -0x48(%rbp),%rdx
mov    $0x200,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1362 <sete+0x1e2>
movsbl -0x250(%rbp),%eax
cmp    $0x23,%eax
jne    127b <sete+0xfb>
jmp    1247 <sete+0xc7>
movsbl -0x250(%rbp),%eax
cmp    $0xa,%eax
jne    1290 <sete+0x110>
jmp    1247 <sete+0xc7>
movl   $0x0,-0x24(%rbp)
lea    -0x250(%rbp),%rdi
lea    0xd7d(%rip),%rsi
call   1090 <strtok@plt>
mov    %rax,-0x268(%rbp)
mov    -0x268(%rbp),%rcx
mov    -0x24(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x24(%rbp)
cltq
mov    %rcx,-0x40(%rbp,%rax,8)
xor    %eax,%eax
mov    %eax,%edi
lea    0xd4f(%rip),%rsi
call   1090 <strtok@plt>
mov    %rax,-0x258(%rbp)
mov    -0x258(%rbp),%rcx
mov    -0x24(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x24(%rbp)
cltq
mov    %rcx,-0x40(%rbp,%rax,8)
xor    %eax,%eax
mov    %eax,%edi
lea    0xd20(%rip),%rsi
call   1090 <strtok@plt>
mov    %rax,-0x260(%rbp)
cmpq   $0x0,-0x260(%rbp)
je     1338 <sete+0x1b8>
mov    -0x260(%rbp),%rcx
mov    -0x24(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x24(%rbp)
cltq
mov    %rcx,-0x40(%rbp,%rax,8)
mov    -0x24(%rbp),%edi
lea    -0x40(%rbp),%rsi
call   1030 <fw_setenv@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
je     135d <sete+0x1dd>
movl   $0x1,-0x4(%rbp)
jmp    1372 <sete+0x1f2>
jmp    1247 <sete+0xc7>
mov    -0x48(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x280,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sete>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x238,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x8(%rsi),%rdi
lea    0x8(%rsp),%rsi
call   1070 <stat@plt>
cmp    $0xffffffff,%eax
je     1281 <sete+0x101>
mov    0x8(%rbx),%rbp
lea    0xe48(%rip),%rsi
mov    %rbp,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     12a8 <sete+0x128>
mov    %rax,%rbx
lea    0x30(%rsp),%rdi
mov    $0x200,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     129c <sete+0x11c>
lea    0x30(%rsp),%r14
lea    0xe2f(%rip),%r15
lea    0xe2a(%rip),%r12
lea    0xe24(%rip),%r13
lea    0x10(%rsp),%rbp
jmp    123f <sete+0xbf>
nopl   0x0(%rax,%rax,1)
mov    %rax,0x20(%rsp)
mov    $0x3,%edi
mov    %rbp,%rsi
call   1030 <fw_setenv@plt>
test   %eax,%eax
jne    12d3 <sete+0x153>
mov    %r14,%rdi
mov    $0x200,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     129c <sete+0x11c>
movzbl 0x30(%rsp),%eax
cmp    $0xa,%al
je     122a <sete+0xaa>
cmp    $0x23,%al
je     122a <sete+0xaa>
mov    %r14,%rdi
mov    %r15,%rsi
call   1090 <strtok@plt>
mov    %rax,0x10(%rsp)
xor    %edi,%edi
mov    %r12,%rsi
call   1090 <strtok@plt>
mov    %rax,0x18(%rsp)
xor    %edi,%edi
mov    %r13,%rsi
call   1090 <strtok@plt>
test   %rax,%rax
jne    1210 <sete+0x90>
mov    $0x2,%edi
jmp    121a <sete+0x9a>
mov    %ebp,%edi
mov    %rbx,%rsi
add    $0x238,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fw_setenv@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    12d8 <sete+0x158>
mov    0x2d31(%rip),%rax
mov    (%rax),%ebx
mov    0x2d20(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xd3c(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    %rax,%rcx
call   1060 <fprintf@plt>
mov    $0x1,%eax
add    $0x238,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [32 x i8] c"Cannot read setenv file %s: %s\0A\00"
@errno = global i32 0
@.str.2 = [2 x i8] c" \00"
@.str.3 = [3 x i8] c" \0A\00"
@.str.4 = [2 x i8] c"\0A\00"
define i32 @sete(i32 %0, i8** %1) {
%3 = alloca %struct.stat
%4 = alloca [3 x i8*]
%5 = alloca [512 x i8]
%6 = bitcast %struct.stat* %3 to i8*
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = call i32 @stat(i8* %8, %struct.stat* %3)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = tail call i32 @fw_setenv(i32 %0, i8** %1)
br label %50
13: ; preds = %2
%14 = load i8*, i8** %7
%15 = bitcast [3 x i8*]* %4 to i8*
%16 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%17 = tail call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %26, label %19
19: ; preds = %13
%20 = call i64 @fgets(i8* %16, i32 512, i32* %17)
%21 = icmp eq i64 %20, 0
br i1 %21, label %46, label %22
22: ; preds = %19
%23 = getelementptr inbounds [3 x i8*], [3 x i8*]* %4, i64 0, i64 0
%24 = getelementptr inbounds [3 x i8*], [3 x i8*]* %4, i64 0, i64 1
%25 = getelementptr inbounds [3 x i8*], [3 x i8*]* %4, i64 0, i64 2
br label %31
26: ; preds = %13
%27 = load i32, i32* @stderr
%28 = load i32, i32* @errno
%29 = tail call i8* @strerror(i32 %28)
%30 = tail call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %14, i8* %29)
br label %48
31: ; preds = %22, %43
%32 = load i8, i8* %16
switch i8 %32, label %33 [
i8 35, label %43
i8 10, label %43
]
33: ; preds = %31
%34 = call i8* @strtok(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %34, i8** %23
%35 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i8* %35, i8** %24
%36 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%37 = icmp eq i8* %36, null
br i1 %37, label %39, label %38
38: ; preds = %33
store i8* %36, i8** %25
br label %39
39: ; preds = %38, %33
%40 = phi i32 [ 3, %38 ], [ 2, %33 ]
%41 = call i32 @fw_setenv(i32 %40, i8** %23)
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %48
43: ; preds = %39, %31, %31
%44 = call i64 @fgets(i8* %16, i32 512, i32* %17)
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %31
46: ; preds = %43, %19
%47 = call i32 @fclose(i32* %17)
br label %48
48: ; preds = %39, %46, %26
%49 = phi i32 [ 1, %26 ], [ 0, %46 ], [ 1, %39 ]
br label %50
50: ; preds = %48, %11
%51 = phi i32 [ %12, %11 ], [ %49, %48 ]
ret i32 %51
}