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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *);
char *getenv(char *);
struct passwd *getpwuid(int /*<<< orphan*/);
int /*<<< orphan*/ getuid();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, int /*<<< orphan*/);
int strlen(char *);
int main(int argc, char *argv[]) {
  struct passwd *pw;
  char path[80];
  char *flavour = NULL;
  char *id = NULL;
  char *build_sys = NULL;
  pw = getpwuid(getuid());
  strcpy(path, pw->pw_dir);
  strcat(path, "/.bashrc");
  FILE *fp;
  fp = fopen((const char *)path, "a+");
  flavour = getenv("FLAVOR");
  if (flavour == NULL || (flavour != NULL && strlen(flavour) < 2))
    fprintf(fp, "\nexport FLAVOR=$(echo $(flavor))\n");
  id = getenv("FLAVOR_ID");
  if (id == NULL || (flavour != NULL && strlen(flavour) < 2))
    fprintf(fp, "\nexport FLAVOR_ID=$(echo $(flavor -d))\n");
  build_sys = getenv("BUILD_SYS");
  if (build_sys == NULL || (flavour != NULL && strlen(flavour) < 2))
    fprintf(fp, "\nexport BUILD_SYS=$(echo $(flavor -b))\n");
  fclose(fp);
  if (flavour == NULL | id == NULL | build_sys == NULL) {
    printf("Shell environment was incomplete - update bash shell\n");
    return (1);
  } else {
    printf("Shell environment OK\n");
    return (0);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x78(%rbp)
movq   $0x0,-0x80(%rbp)
movq   $0x0,-0x88(%rbp)
mov    $0x0,%al
call   1080 <getuid@plt>
mov    %eax,%edi
call   1060 <getpwuid@plt>
mov    %rax,-0x18(%rbp)
lea    -0x70(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
call   1040 <strcpy@plt>
lea    -0x70(%rbp),%rdi
lea    0xe00(%rip),%rsi
call   10c0 <strcat@plt>
lea    -0x70(%rbp),%rdi
lea    0xdf9(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x90(%rbp)
lea    0xde9(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x78(%rbp)
je     1254 <main+0xb4>
cmpq   $0x0,-0x78(%rbp)
je     1267 <main+0xc7>
mov    -0x78(%rbp),%rdi
call   1070 <strlen@plt>
cmp    $0x2,%eax
jge    1267 <main+0xc7>
mov    -0x90(%rbp),%rdi
lea    0xdb1(%rip),%rsi
call   10a0 <fprintf@plt>
lea    0xdc7(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x80(%rbp)
cmpq   $0x0,-0x80(%rbp)
je     129f <main+0xff>
cmpq   $0x0,-0x78(%rbp)
je     12b2 <main+0x112>
mov    -0x78(%rbp),%rdi
call   1070 <strlen@plt>
cmp    $0x2,%eax
jge    12b2 <main+0x112>
mov    -0x90(%rbp),%rdi
lea    0xd92(%rip),%rsi
call   10a0 <fprintf@plt>
lea    0xdae(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x88(%rbp)
cmpq   $0x0,-0x88(%rbp)
je     12f0 <main+0x150>
cmpq   $0x0,-0x78(%rbp)
je     1303 <main+0x163>
mov    -0x78(%rbp),%rdi
call   1070 <strlen@plt>
cmp    $0x2,%eax
jge    1303 <main+0x163>
mov    -0x90(%rbp),%rdi
lea    0xd73(%rip),%rsi
call   10a0 <fprintf@plt>
mov    -0x90(%rbp),%rdi
call   1050 <fclose@plt>
cmpq   $0x0,-0x78(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%eax
cmpq   $0x0,-0x80(%rbp)
sete   %cl
and    $0x1,%cl
movzbl %cl,%ecx
or     %ecx,%eax
cmpq   $0x0,-0x88(%rbp)
sete   %cl
and    $0x1,%cl
movzbl %cl,%ecx
or     %ecx,%eax
cmp    $0x0,%eax
je     1360 <main+0x1c0>
lea    0xd4a(%rip),%rdi
call   1090 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1373 <main+0x1d3>
lea    0xd68(%rip),%rdi
call   1090 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x58,%rsp
xor    %eax,%eax
call   1090 <getuid@plt>
mov    %eax,%edi
call   1070 <getpwuid@plt>
mov    (%rax),%esi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1040 <strcpy@plt>
lea    0xe34(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <strcat@plt>
lea    0xe2e(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <fopen@plt>
mov    %rax,%r14
lea    0xe1f(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1207 <main+0x67>
mov    %rbx,%rdi
call   1080 <strlen@plt>
cmp    $0x1,%eax
jg     1252 <main+0xb2>
lea    0xe05(%rip),%rdi
mov    $0x21,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   10c0 <fwrite@plt>
lea    0xe0e(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1275 <main+0xd5>
test   %rbx,%rbx
jne    1263 <main+0xc3>
lea    0xe2a(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
jne    12a7 <main+0x107>
mov    $0x1,%bpl
xor    %r15d,%r15d
jmp    12e5 <main+0x145>
lea    0xddc(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1275 <main+0xd5>
mov    %rbx,%rdi
call   1080 <strlen@plt>
cmp    $0x1,%eax
jg     12bd <main+0x11d>
xor    %r15d,%r15d
jmp    1278 <main+0xd8>
mov    $0x1,%r15b
lea    0xdc0(%rip),%rdi
mov    $0x27,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   10c0 <fwrite@plt>
lea    0xdcf(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     12e2 <main+0x142>
test   %rbx,%rbx
jne    12d1 <main+0x131>
mov    %r14,%rdi
call   1060 <fclose@plt>
mov    $0x1,%ebx
lea    0xdf3(%rip),%rdi
jmp    1328 <main+0x188>
lea    0xda3(%rip),%rdi
call   1030 <getenv@plt>
xor    %r15d,%r15d
test   %rax,%rax
je     12e2 <main+0x142>
mov    %rbx,%rdi
call   1080 <strlen@plt>
xor    %ebp,%ebp
cmp    $0x1,%eax
jg     12fe <main+0x15e>
jmp    12e5 <main+0x145>
mov    $0x1,%bpl
lea    0xd85(%rip),%rdi
mov    $0x27,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   10c0 <fwrite@plt>
test   %rbx,%rbx
sete   %bl
mov    %r14,%rdi
call   1060 <fclose@plt>
or     %r15b,%bpl
or     %bl,%bpl
lea    0xd95(%rip),%rax
lea    0xd79(%rip),%rdi
cmovne %rax,%rdi
movzbl %bpl,%ebx
call   1050 <puts@plt>
mov    %ebx,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.passwd = type { i32 }
@.str = [9 x i8] c"/.bashrc\00"
@.str.1 = [3 x i8] c"a+\00"
@.str.2 = [7 x i8] c"FLAVOR\00"
@.str.3 = [34 x i8] c"\0Aexport FLAVOR=$(echo $(flavor))\0A\00"
@.str.4 = [10 x i8] c"FLAVOR_ID\00"
@.str.5 = [40 x i8] c"\0Aexport FLAVOR_ID=$(echo $(flavor -d))\0A\00"
@.str.6 = [10 x i8] c"BUILD_SYS\00"
@.str.7 = [40 x i8] c"\0Aexport BUILD_SYS=$(echo $(flavor -b))\0A\00"
@.str.8 = [54 x i8] c"Shell environment was incomplete - update bash shell\0A\00"
@.str.9 = [22 x i8] c"Shell environment OK\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.passwd*
%7 = alloca [80 x i8]
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %8
store i8* null, i8** %9
store i8* null, i8** %10
%12 = call i32 (...) @getuid()
%13 = call %struct.passwd* @getpwuid(i32 %12)
store %struct.passwd* %13, %struct.passwd** %6
%14 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%15 = load %struct.passwd*, %struct.passwd** %6
%16 = getelementptr inbounds %struct.passwd, %struct.passwd* %15, i32 0, i32 0
%17 = load i32, i32* %16
%18 = call i32 @strcpy(i8* %14, i32 %17)
%19 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%20 = call i32 @strcat(i8* %19, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%21 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %22, i32** %11
%23 = call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
store i8* %23, i8** %8
%24 = load i8*, i8** %8
%25 = icmp eq i8* %24, null
br i1 %25, label %33, label %26
26: ; preds = %2
%27 = load i8*, i8** %8
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %36
29: ; preds = %26
%30 = load i8*, i8** %8
%31 = call i32 @strlen(i8* %30)
%32 = icmp slt i32 %31, 2
br i1 %32, label %33, label %36
33: ; preds = %29, %2
%34 = load i32*, i32** %11
%35 = call i32 @fprintf(i32* %34, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
br label %36
36: ; preds = %33, %29, %26
%37 = call i8* @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
store i8* %37, i8** %9
%38 = load i8*, i8** %9
%39 = icmp eq i8* %38, null
br i1 %39, label %47, label %40
40: ; preds = %36
%41 = load i8*, i8** %8
%42 = icmp ne i8* %41, null
br i1 %42, label %43, label %50
43: ; preds = %40
%44 = load i8*, i8** %8
%45 = call i32 @strlen(i8* %44)
%46 = icmp slt i32 %45, 2
br i1 %46, label %47, label %50
47: ; preds = %43, %36
%48 = load i32*, i32** %11
%49 = call i32 @fprintf(i32* %48, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0))
br label %50
50: ; preds = %47, %43, %40
%51 = call i8* @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
store i8* %51, i8** %10
%52 = load i8*, i8** %10
%53 = icmp eq i8* %52, null
br i1 %53, label %61, label %54
54: ; preds = %50
%55 = load i8*, i8** %8
%56 = icmp ne i8* %55, null
br i1 %56, label %57, label %64
57: ; preds = %54
%58 = load i8*, i8** %8
%59 = call i32 @strlen(i8* %58)
%60 = icmp slt i32 %59, 2
br i1 %60, label %61, label %64
61: ; preds = %57, %50
%62 = load i32*, i32** %11
%63 = call i32 @fprintf(i32* %62, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.7, i64 0, i64 0))
br label %64
64: ; preds = %61, %57, %54
%65 = load i32*, i32** %11
%66 = call i32 @fclose(i32* %65)
%67 = load i8*, i8** %8
%68 = icmp eq i8* %67, null
%69 = zext i1 %68 to i32
%70 = load i8*, i8** %9
%71 = icmp eq i8* %70, null
%72 = zext i1 %71 to i32
%73 = or i32 %69, %72
%74 = load i8*, i8** %10
%75 = icmp eq i8* %74, null
%76 = zext i1 %75 to i32
%77 = or i32 %73, %76
%78 = icmp ne i32 %77, 0
br i1 %78, label %79, label %81
79: ; preds = %64
%80 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.8, i64 0, i64 0))
store i32 1, i32* %3
br label %83
81: ; preds = %64
%82 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0))
store i32 0, i32* %3
br label %83
83: ; preds = %81, %79
%84 = load i32, i32* %3
ret i32 %84
}

LLVM IR (-O2):
%struct.passwd = type { i32 }
@.str = [9 x i8] c"/.bashrc\00"
@.str.1 = [3 x i8] c"a+\00"
@.str.2 = [7 x i8] c"FLAVOR\00"
@.str.3 = [34 x i8] c"\0Aexport FLAVOR=$(echo $(flavor))\0A\00"
@.str.4 = [10 x i8] c"FLAVOR_ID\00"
@.str.5 = [40 x i8] c"\0Aexport FLAVOR_ID=$(echo $(flavor -d))\0A\00"
@.str.6 = [10 x i8] c"BUILD_SYS\00"
@.str.7 = [40 x i8] c"\0Aexport BUILD_SYS=$(echo $(flavor -b))\0A\00"
@str = [21 x i8] c"Shell environment OK\00"
@str.10 = [53 x i8] c"Shell environment was incomplete - update bash shell\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [80 x i8]
%4 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%5 = tail call i32 (...) @getuid()
%6 = tail call %struct.passwd* @getpwuid(i32 %5)
%7 = getelementptr inbounds %struct.passwd, %struct.passwd* %6, i64 0, i32 0
%8 = load i32, i32* %7
%9 = call i32 @strcpy(i8* %4, i32 %8)
%10 = call i32 @strcat(i8* %4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%11 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%12 = call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i8* %12, null
br i1 %13, label %17, label %14
14: ; preds = %2
%15 = call i32 @strlen(i8* %12)
%16 = icmp slt i32 %15, 2
br i1 %16, label %17, label %21
17: ; preds = %2, %14
%18 = call i64 @fwrite(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i64 33, i64 1, i32* %11)
%19 = call i8* @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%20 = icmp eq i8* %19, null
br i1 %20, label %28, label %24
21: ; preds = %14
%22 = call i8* @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%23 = icmp eq i8* %22, null
br i1 %23, label %28, label %25
24: ; preds = %17
br i1 %13, label %33, label %25
25: ; preds = %21, %24
%26 = call i32 @strlen(i8* %12)
%27 = icmp slt i32 %26, 2
br i1 %27, label %28, label %36
28: ; preds = %17, %25, %21
%29 = phi i1 [ true, %21 ], [ false, %25 ], [ true, %17 ]
%30 = call i64 @fwrite(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i64 39, i64 1, i32* %11)
%31 = call i8* @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
%32 = icmp eq i8* %31, null
br i1 %32, label %44, label %39
33: ; preds = %24
%34 = call i8* @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
%35 = icmp eq i8* %34, null
br i1 %35, label %44, label %48
36: ; preds = %25
%37 = call i8* @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
%38 = icmp eq i8* %37, null
br i1 %38, label %44, label %40
39: ; preds = %28
br i1 %13, label %48, label %40
40: ; preds = %36, %39
%41 = phi i1 [ %29, %39 ], [ false, %36 ]
%42 = call i32 @strlen(i8* %12)
%43 = icmp slt i32 %42, 2
br i1 %43, label %44, label %50
44: ; preds = %33, %36, %40, %28
%45 = phi i1 [ true, %36 ], [ false, %40 ], [ true, %28 ], [ true, %33 ]
%46 = phi i1 [ false, %36 ], [ %41, %40 ], [ %29, %28 ], [ false, %33 ]
%47 = call i64 @fwrite(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.7, i64 0, i64 0), i64 39, i64 1, i32* %11)
br label %50
48: ; preds = %39, %33
%49 = call i32 @fclose(i32* %11)
br label %58
50: ; preds = %44, %40
%51 = phi i1 [ %45, %44 ], [ false, %40 ]
%52 = phi i1 [ %46, %44 ], [ %41, %40 ]
%53 = call i32 @fclose(i32* %11)
%54 = or i1 %13, %52
%55 = or i1 %51, %54
%56 = select i1 %55, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @str.10, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0)
%57 = zext i1 %55 to i32
br label %58
58: ; preds = %50, %48
%59 = phi i8* [ getelementptr inbounds ([53 x i8], [53 x i8]* @str.10, i64 0, i64 0), %48 ], [ %56, %50 ]
%60 = phi i32 [ 1, %48 ], [ %57, %50 ]
%61 = call i32 @puts(i8* dereferenceable(1) %59)
ret i32 %60
}