#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*/ pid_t;

/* Variables and functions */
int /*<<< orphan*/ fork();
char *getenv(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putenv(char *);
int /*<<< orphan*/ sleep(int);
int main(int argc, char *argv[]) {
  char a[] = "ABC=\"abc\"";
  char b[] = "ABC=\"xyz\"";
  pid_t childPid;
  printf("a=%s\n", a);
  putenv(a);
  switch (childPid = fork()) {
  case -1:
    printf("error\n");
    break;
  case 0:
    while (1) {
      printf("child %s\n", getenv("ABC"));
      sleep(1);
    }
    break;
  default:
    printf("parent %s\n", getenv("ABC"));
    sleep(5);
    printf("changing ABC\n");
    putenv(b);
    printf("parent %s\n", getenv("ABC"));
    sleep(5);
    break;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movabs $0x636261223d434241,%rax
61 62 63
mov    %rax,-0x20(%rbp)
movw   $0x22,-0x18(%rbp)
movabs $0x7a7978223d434241,%rax
78 79 7a
mov    %rax,-0x30(%rbp)
movw   $0x22,-0x28(%rbp)
lea    0xe7f(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x39(%rbp)
lea    -0x20(%rbp),%rsi
mov    %rsi,-0x48(%rbp)
call   1040 <printf@plt>
mov    -0x48(%rbp),%rdi
call   1050 <putenv@plt>
mov    -0x39(%rbp),%al
call   1070 <fork@plt>
mov    %eax,-0x34(%rbp)
mov    %eax,%ecx
mov    %ecx,-0x38(%rbp)
sub    $0xffffffff,%eax
je     11de <main+0x8e>
jmp    11ce <main+0x7e>
mov    -0x38(%rbp),%eax
test   %eax,%eax
je     11f1 <main+0xa1>
jmp    1222 <main+0xd2>
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1287 <main+0x137>
jmp    11f6 <main+0xa6>
lea    0xe2e(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rsi
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
jmp    11f6 <main+0xa6>
lea    0xe02(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rsi
lea    0xdf7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x5,%edi
call   1060 <sleep@plt>
lea    0xdea(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x30(%rbp),%rdi
call   1050 <putenv@plt>
lea    0xdc4(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rsi
lea    0xdb9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x5,%edi
call   1060 <sleep@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
movabs $0x636261223d434241,%rax
61 62 63
mov    %rax,0x18(%rsp)
movw   $0x22,0x20(%rsp)
movabs $0x7a7978223d434241,%rax
78 79 7a
mov    %rax,0x8(%rsp)
movw   $0x22,0x10(%rsp)
lea    0xe7a(%rip),%rdi
lea    0x18(%rsp),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1060 <putenv@plt>
xor    %eax,%eax
call   1080 <fork@plt>
cmp    $0xffffffff,%eax
je     11f1 <main+0x91>
lea    0xe7a(%rip),%r14
test   %eax,%eax
jne    11ff <main+0x9f>
lea    0xe4b(%rip),%rbx
nop
mov    %r14,%rdi
call   1030 <getenv@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
jmp    11d0 <main+0x70>
lea    0xe37(%rip),%rdi
call   1040 <puts@plt>
jmp    125a <main+0xfa>
mov    %r14,%rdi
call   1030 <getenv@plt>
lea    0xe16(%rip),%rbx
mov    %rbx,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x5,%edi
call   1070 <sleep@plt>
lea    0xe09(%rip),%rdi
call   1040 <puts@plt>
lea    0x8(%rsp),%rdi
call   1060 <putenv@plt>
mov    %r14,%rdi
call   1030 <getenv@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x5,%edi
call   1070 <sleep@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.a = [10 x i8] c"ABC=\22abc\22\00"
@__const.main.b = [10 x i8] c"ABC=\22xyz\22\00"
@.str = [6 x i8] c"a=%s\0A\00"
@.str.1 = [7 x i8] c"error\0A\00"
@.str.2 = [10 x i8] c"child %s\0A\00"
@.str.3 = [4 x i8] c"ABC\00"
@.str.4 = [11 x i8] c"parent %s\0A\00"
@.str.5 = [14 x i8] c"changing ABC\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [10 x i8]
%7 = alloca [10 x i8]
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = bitcast [10 x i8]* %6 to i8*
%10 = bitcast [10 x i8]* %7 to i8*
%11 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%14 = call i32 @putenv(i8* %13)
%15 = call i32 (...) @fork()
store i32 %15, i32* %8
switch i32 %15, label %23 [
i32 -1, label %16
i32 0, label %18
]
16: ; preds = %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %33
18: ; preds = %2
br label %19
19: ; preds = %18, %19
%20 = call i8* @getenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %20)
%22 = call i32 @sleep(i32 1)
br label %19
23: ; preds = %2
%24 = call i8* @getenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %24)
%26 = call i32 @sleep(i32 5)
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
%28 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%29 = call i32 @putenv(i8* %28)
%30 = call i8* @getenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %30)
%32 = call i32 @sleep(i32 5)
br label %33
33: ; preds = %23, %16
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
@__const.main.a = [10 x i8] c"ABC=\22abc\22\00"
@__const.main.b = [10 x i8] c"ABC=\22xyz\22\00"
@.str = [6 x i8] c"a=%s\0A\00"
@.str.2 = [10 x i8] c"child %s\0A\00"
@.str.3 = [4 x i8] c"ABC\00"
@.str.4 = [11 x i8] c"parent %s\0A\00"
@str = [6 x i8] c"error\00"
@str.6 = [13 x i8] c"changing ABC\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [10 x i8]
%4 = alloca [10 x i8]
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %5)
%8 = call i32 @putenv(i8* %5)
%9 = call i32 (...) @fork()
switch i32 %9, label %16 [
i32 -1, label %10
i32 0, label %12
]
10: ; preds = %2
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
br label %25
12: ; preds = %2, %12
%13 = call i8* @getenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %13)
%15 = call i32 @sleep(i32 1)
br label %12
16: ; preds = %2
%17 = call i8* @getenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %17)
%19 = call i32 @sleep(i32 5)
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.6, i64 0, i64 0))
%21 = call i32 @putenv(i8* %6)
%22 = call i8* @getenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %22)
%24 = call i32 @sleep(i32 5)
br label %25
25: ; preds = %16, %10
ret i32 0
}