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

/* Variables and functions */
char *strchr(char *, char);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ tst_resm(int, char *, ...);
int cmp_env_strings(char *pstring, char *cstring) {
  char *penv, *cenv, *pvalue, *cvalue;
  penv = pstring;
  if ((pvalue = strchr(pstring, ':')) == NULL) {
    tst_resm(2,
             "internal error - parent's env string not in correct format:'%s'",
             pstring);
    return -1;
  } else {
    *pvalue = '\0';
    pvalue++;
    if (*pvalue == '\0') {
      tst_resm(2, "internal error - missing parent's env value");
      return -1;
    }
  }
  cenv = cstring;
  if ((cvalue = strchr(cstring, ':')) == NULL) {
    tst_resm(2,
             "internal error - parent's env string not in correct format:'%s'",
             cstring);
    return -1;
  } else {
    *cvalue = '\0';
    cvalue++;
    if (*cvalue == '\0') {
      tst_resm(2, "internal error - missing child's env value");
      return -1;
    }
  }
  if (strcmp(penv, cenv) != 0) {
    tst_resm(2, "internal error - parent(%s) != child (%s) env", penv, cenv);
    return -1;
  }
  if (strcmp(pvalue, cvalue) != 0) {
    tst_resm(1, "Env var %s changed after fork(), parent's %s, child's %s",
             penv, pvalue, cvalue);
  } else {
    tst_resm(0, "Env var %s unchanged after fork(): %s", penv, cvalue);
  }
  return 0;
}


x86 assembly (clang, -O0):
<cmp_env_strings>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    1187 <cmp_env_strings+0x57>
mov    -0x10(%rbp),%rdx
mov    $0x2,%edi
lea    0xe8c(%rip),%rsi
mov    $0x0,%al
call   1050 <tst_resm@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12f4 <cmp_env_strings+0x1c4>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11c9 <cmp_env_strings+0x99>
mov    $0x2,%edi
lea    0xe8a(%rip),%rsi
mov    $0x0,%al
call   1050 <tst_resm@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12f4 <cmp_env_strings+0x1c4>
jmp    11ce <cmp_env_strings+0x9e>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    1215 <cmp_env_strings+0xe5>
mov    -0x18(%rbp),%rdx
mov    $0x2,%edi
lea    0xdfe(%rip),%rsi
mov    $0x0,%al
call   1050 <tst_resm@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12f4 <cmp_env_strings+0x1c4>
mov    -0x38(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1257 <cmp_env_strings+0x127>
mov    $0x2,%edi
lea    0xe28(%rip),%rsi
mov    $0x0,%al
call   1050 <tst_resm@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12f4 <cmp_env_strings+0x1c4>
jmp    125c <cmp_env_strings+0x12c>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     129a <cmp_env_strings+0x16a>
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    $0x2,%edi
lea    0xe10(%rip),%rsi
mov    $0x0,%al
call   1050 <tst_resm@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12f4 <cmp_env_strings+0x1c4>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     12d5 <cmp_env_strings+0x1a5>
mov    -0x20(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x38(%rbp),%r8
mov    $0x1,%edi
lea    0xdfc(%rip),%rsi
mov    $0x0,%al
call   1050 <tst_resm@plt>
jmp    12ed <cmp_env_strings+0x1bd>
mov    -0x20(%rbp),%rdx
mov    -0x38(%rbp),%rcx
xor    %edi,%edi
lea    0xe18(%rip),%rsi
mov    $0x0,%al
call   1050 <tst_resm@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmp_env_strings>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x3a,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     11a2 <cmp_env_strings+0x72>
mov    %rax,%rbx
movb   $0x0,(%rax)
cmpb   $0x0,0x1(%rax)
je     11b3 <cmp_env_strings+0x83>
mov    %r14,%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     11bc <cmp_env_strings+0x8c>
mov    %rax,%r12
movb   $0x0,(%rax)
cmpb   $0x0,0x1(%rax)
je     11d4 <cmp_env_strings+0xa4>
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11f7 <cmp_env_strings+0xc7>
lea    0xf09(%rip),%rsi
mov    $0x2,%edi
mov    %r15,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1050 <tst_resm@plt>
jmp    11e7 <cmp_env_strings+0xb7>
lea    0xe57(%rip),%rsi
mov    $0x2,%edi
mov    %r15,%rdx
jmp    11cb <cmp_env_strings+0x9b>
lea    0xe86(%rip),%rsi
jmp    11db <cmp_env_strings+0xab>
lea    0xe3d(%rip),%rsi
mov    $0x2,%edi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <tst_resm@plt>
jmp    11e7 <cmp_env_strings+0xb7>
lea    0xe91(%rip),%rsi
mov    $0x2,%edi
xor    %eax,%eax
call   1050 <tst_resm@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
add    $0x1,%rbx
add    $0x1,%r12
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     122f <cmp_env_strings+0xff>
lea    0xeaf(%rip),%rsi
xor    %ebp,%ebp
mov    $0x1,%edi
mov    %r15,%rdx
mov    %rbx,%rcx
mov    %r12,%r8
xor    %eax,%eax
call   1050 <tst_resm@plt>
jmp    11ec <cmp_env_strings+0xbc>
lea    0xec8(%rip),%rsi
xor    %ebp,%ebp
xor    %edi,%edi
mov    %r15,%rdx
mov    %r12,%rcx
xor    %eax,%eax
call   1050 <tst_resm@plt>
jmp    11ec <cmp_env_strings+0xbc>

LLVM IR (-O0):
@.str = [64 x i8] c"internal error - parent's env string not in correct format:'%s'\00"
@.str.1 = [44 x i8] c"internal error - missing parent's env value\00"
@.str.2 = [43 x i8] c"internal error - missing child's env value\00"
@.str.3 = [46 x i8] c"internal error - parent(%s) != child (%s) env\00"
@.str.4 = [57 x i8] c"Env var %s changed after fork(), parent's %s, child's %s\00"
@.str.5 = [38 x i8] c"Env var %s unchanged after fork(): %s\00"
define i32 @cmp_env_strings(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = load i8*, i8** %4
store i8* %10, i8** %6
%11 = load i8*, i8** %4
%12 = call i8* @strchr(i8* %11, i8 signext 58)
store i8* %12, i8** %8
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = load i8*, i8** %4
%16 = call i32 (i32, i8*, ...) @tst_resm(i32 2, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0), i8* %15)
store i32 -1, i32* %3
br label %71
17: ; preds = %2
%18 = load i8*, i8** %8
store i8 0, i8* %18
%19 = load i8*, i8** %8
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %8
%21 = load i8*, i8** %8
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %17
%26 = call i32 (i32, i8*, ...) @tst_resm(i32 2, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %71
27: ; preds = %17
br label %28
28: ; preds = %27
%29 = load i8*, i8** %5
store i8* %29, i8** %7
%30 = load i8*, i8** %5
%31 = call i8* @strchr(i8* %30, i8 signext 58)
store i8* %31, i8** %9
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %36
33: ; preds = %28
%34 = load i8*, i8** %5
%35 = call i32 (i32, i8*, ...) @tst_resm(i32 2, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0), i8* %34)
store i32 -1, i32* %3
br label %71
36: ; preds = %28
%37 = load i8*, i8** %9
store i8 0, i8* %37
%38 = load i8*, i8** %9
%39 = getelementptr inbounds i8, i8* %38, i32 1
store i8* %39, i8** %9
%40 = load i8*, i8** %9
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %36
%45 = call i32 (i32, i8*, ...) @tst_resm(i32 2, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %71
46: ; preds = %36
br label %47
47: ; preds = %46
%48 = load i8*, i8** %6
%49 = load i8*, i8** %7
%50 = call i64 @strcmp(i8* %48, i8* %49)
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %56
52: ; preds = %47
%53 = load i8*, i8** %6
%54 = load i8*, i8** %7
%55 = call i32 (i32, i8*, ...) @tst_resm(i32 2, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0), i8* %53, i8* %54)
store i32 -1, i32* %3
br label %71
56: ; preds = %47
%57 = load i8*, i8** %8
%58 = load i8*, i8** %9
%59 = call i64 @strcmp(i8* %57, i8* %58)
%60 = icmp ne i64 %59, 0
br i1 %60, label %61, label %66
61: ; preds = %56
%62 = load i8*, i8** %6
%63 = load i8*, i8** %8
%64 = load i8*, i8** %9
%65 = call i32 (i32, i8*, ...) @tst_resm(i32 1, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.4, i64 0, i64 0), i8* %62, i8* %63, i8* %64)
br label %70
66: ; preds = %56
%67 = load i8*, i8** %6
%68 = load i8*, i8** %9
%69 = call i32 (i32, i8*, ...) @tst_resm(i32 0, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), i8* %67, i8* %68)
br label %70
70: ; preds = %66, %61
store i32 0, i32* %3
br label %71
71: ; preds = %70, %52, %44, %33, %25, %14
%72 = load i32, i32* %3
ret i32 %72
}

LLVM IR (-O2):
@.str = [64 x i8] c"internal error - parent's env string not in correct format:'%s'\00"
@.str.1 = [44 x i8] c"internal error - missing parent's env value\00"
@.str.2 = [43 x i8] c"internal error - missing child's env value\00"
@.str.3 = [46 x i8] c"internal error - parent(%s) != child (%s) env\00"
@.str.4 = [57 x i8] c"Env var %s changed after fork(), parent's %s, child's %s\00"
@.str.5 = [38 x i8] c"Env var %s unchanged after fork(): %s\00"
define i32 @cmp_env_strings(i8* %0, i8* %1) {
%3 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 58)
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 (i32, i8*, ...) @tst_resm(i32 2, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %36
7: ; preds = %2
store i8 0, i8* %3
%8 = getelementptr inbounds i8, i8* %3, i64 1
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = tail call i32 (i32, i8*, ...) @tst_resm(i32 2, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
br label %36
13: ; preds = %7
%14 = tail call i8* @strchr(i8* dereferenceable(1) %1, i8 signext 58)
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = tail call i32 (i32, i8*, ...) @tst_resm(i32 2, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %36
18: ; preds = %13
store i8 0, i8* %14
%19 = getelementptr inbounds i8, i8* %14, i64 1
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = tail call i32 (i32, i8*, ...) @tst_resm(i32 2, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
br label %36
24: ; preds = %18
%25 = tail call i64 @strcmp(i8* %0, i8* %1)
%26 = icmp eq i64 %25, 0
br i1 %26, label %29, label %27
27: ; preds = %24
%28 = tail call i32 (i32, i8*, ...) @tst_resm(i32 2, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0), i8* %0, i8* %1)
br label %36
29: ; preds = %24
%30 = tail call i64 @strcmp(i8* %8, i8* %19)
%31 = icmp eq i64 %30, 0
br i1 %31, label %34, label %32
32: ; preds = %29
%33 = tail call i32 (i32, i8*, ...) @tst_resm(i32 1, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.4, i64 0, i64 0), i8* %0, i8* %8, i8* %19)
br label %36
34: ; preds = %29
%35 = tail call i32 (i32, i8*, ...) @tst_resm(i32 0, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), i8* %0, i8* %19)
br label %36
36: ; preds = %32, %34, %27, %22, %16, %11, %5
%37 = phi i32 [ -1, %5 ], [ -1, %11 ], [ -1, %16 ], [ -1, %22 ], [ -1, %27 ], [ 0, %34 ], [ 0, %32 ]
ret i32 %37
}