#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 *getenv(char *);
const char *gethgcmd(void) {
  static const char *hgcmd = NULL;
  if (!hgcmd) {
    hgcmd = getenv("CHGHG");
    if (!hgcmd || hgcmd[0] == '\0')
      hgcmd = getenv("HG");
    if (!hgcmd || hgcmd[0] == '\0')
      hgcmd = "hg";
  }
  return hgcmd;
}


x86 assembly (clang, -O0):
<gethgcmd>:
push   %rbp
mov    %rsp,%rbp
cmpq   $0x0,0x2f14(%rip)
jne    119d <gethgcmd+0x8d>
lea    0xed7(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,0x2efb(%rip)
cmpq   $0x0,0x2ef3(%rip)
je     1156 <gethgcmd+0x46>
mov    0x2ee6(%rip),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1169 <gethgcmd+0x59>
lea    0xea6(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,0x2ec7(%rip)
cmpq   $0x0,0x2ebf(%rip)
je     118a <gethgcmd+0x7a>
mov    0x2eb2(%rip),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1198 <gethgcmd+0x88>
lea    0xe75(%rip),%rax
mov    %rax,0x2e98(%rip)
jmp    119d <gethgcmd+0x8d>
mov    0x2e8c(%rip),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<gethgcmd>:
push   %rax
mov    0x2f18(%rip),%rax
test   %rax,%rax
je     111f <gethgcmd+0xf>
pop    %rcx
ret
lea    0xeda(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,0x2efe(%rip)
test   %rax,%rax
je     113c <gethgcmd+0x2c>
cmpb   $0x0,(%rax)
jne    111d <gethgcmd+0xd>
lea    0xec0(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,0x2ee1(%rip)
test   %rax,%rax
je     1159 <gethgcmd+0x49>
cmpb   $0x0,(%rax)
jne    111d <gethgcmd+0xd>
lea    0xea6(%rip),%rax
mov    %rax,0x2ec9(%rip)
pop    %rcx
ret

LLVM IR (-O0):
@gethgcmd.hgcmd = internal global i8* null
@.str = [6 x i8] c"CHGHG\00"
@.str.1 = [3 x i8] c"HG\00"
@.str.2 = [3 x i8] c"hg\00"
define i8* @gethgcmd() {
%1 = load i8*, i8** @gethgcmd.hgcmd
%2 = icmp ne i8* %1, null
br i1 %2, label %26, label %3
3: ; preds = %0
%4 = call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i8* %4, i8** @gethgcmd.hgcmd
%5 = load i8*, i8** @gethgcmd.hgcmd
%6 = icmp ne i8* %5, null
br i1 %6, label %7, label %13
7: ; preds = %3
%8 = load i8*, i8** @gethgcmd.hgcmd
%9 = getelementptr inbounds i8, i8* %8, i64 0
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %7, %3
%14 = call i8* @getenv(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i8* %14, i8** @gethgcmd.hgcmd
br label %15
15: ; preds = %13, %7
%16 = load i8*, i8** @gethgcmd.hgcmd
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %24
18: ; preds = %15
%19 = load i8*, i8** @gethgcmd.hgcmd
%20 = getelementptr inbounds i8, i8* %19, i64 0
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %18, %15
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** @gethgcmd.hgcmd
br label %25
25: ; preds = %24, %18
br label %26
26: ; preds = %25, %0
%27 = load i8*, i8** @gethgcmd.hgcmd
ret i8* %27
}

LLVM IR (-O2):
@gethgcmd.hgcmd = internal unnamed_addr global i8* null
@.str = [6 x i8] c"CHGHG\00"
@.str.1 = [3 x i8] c"HG\00"
@.str.2 = [3 x i8] c"hg\00"
define i8* @gethgcmd() {
%1 = load i8*, i8** @gethgcmd.hgcmd
%2 = icmp eq i8* %1, null
br i1 %2, label %3, label %16
3: ; preds = %0
%4 = tail call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i8* %4, i8** @gethgcmd.hgcmd
%5 = icmp eq i8* %4, null
br i1 %5, label %9, label %6
6: ; preds = %3
%7 = load i8, i8* %4
%8 = icmp eq i8 %7, 0
br i1 %8, label %9, label %16
9: ; preds = %3, %6
%10 = tail call i8* @getenv(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i8* %10, i8** @gethgcmd.hgcmd
%11 = icmp eq i8* %10, null
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = load i8, i8* %10
%14 = icmp eq i8 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %12, %9
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** @gethgcmd.hgcmd
br label %16
16: ; preds = %6, %12, %15, %0
%17 = phi i8* [ %4, %6 ], [ %10, %12 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), %15 ], [ %1, %0 ]
ret i8* %17
}