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

/* Variables and functions */
char *getenv(char *);
int /*<<< orphan*/ strncmp(char const *, char const *, int);
const char *InstanceNumberAsStr(void) {
  static const char kUserPrefix[] = "cvd-";
  const char *user = getenv("USER");
  if (user && !strncmp(user, kUserPrefix, sizeof(kUserPrefix) - 1)) {
    return user + sizeof(kUserPrefix) - 1;
  }
  return "01";
}


x86 assembly (clang, -O0):
<InstanceNumberAsStr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xed6(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1176 <InstanceNumberAsStr+0x56>
mov    -0x10(%rbp),%rdi
lea    0xeb2(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    1176 <InstanceNumberAsStr+0x56>
mov    -0x10(%rbp),%rax
add    $0x5,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x8(%rbp)
jmp    1181 <InstanceNumberAsStr+0x61>
lea    0xe8d(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<InstanceNumberAsStr>:
push   %r14
push   %rbx
push   %rax
lea    0xeda(%rip),%rdi
call   1030 <getenv@plt>
lea    0xed3(%rip),%r14
test   %rax,%rax
je     115e <InstanceNumberAsStr+0x3e>
mov    %rax,%rbx
lea    0xeba(%rip),%rsi
mov    %rax,%rdi
mov    $0x4,%edx
call   1040 <strncmp@plt>
test   %eax,%eax
jne    115e <InstanceNumberAsStr+0x3e>
add    $0x4,%rbx
mov    %rbx,%r14
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@InstanceNumberAsStr.kUserPrefix = internal constant [5 x i8] c"cvd-\00"
@.str = [5 x i8] c"USER\00"
@.str.1 = [3 x i8] c"01\00"
define i8* @InstanceNumberAsStr() {
%1 = alloca i8*
%2 = alloca i8*
%3 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %3, i8** %2
%4 = load i8*, i8** %2
%5 = icmp ne i8* %4, null
br i1 %5, label %6, label %14
6: ; preds = %0
%7 = load i8*, i8** %2
%8 = call i32 @strncmp(i8* %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @InstanceNumberAsStr.kUserPrefix, i64 0, i64 0), i32 4)
%9 = icmp ne i32 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %6
%11 = load i8*, i8** %2
%12 = getelementptr inbounds i8, i8* %11, i64 5
%13 = getelementptr inbounds i8, i8* %12, i64 -1
store i8* %13, i8** %1
br label %15
14: ; preds = %6, %0
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %1
br label %15
15: ; preds = %14, %10
%16 = load i8*, i8** %1
ret i8* %16
}

LLVM IR (-O2):
@InstanceNumberAsStr.kUserPrefix = internal constant [5 x i8] c"cvd-\00"
@.str = [5 x i8] c"USER\00"
@.str.1 = [3 x i8] c"01\00"
define i8* @InstanceNumberAsStr() {
%1 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i8* %1, null
br i1 %2, label %8, label %3
3: ; preds = %0
%4 = tail call i32 @strncmp(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @InstanceNumberAsStr.kUserPrefix, i64 0, i64 0), i32 4)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = getelementptr inbounds i8, i8* %1, i64 4
br label %8
8: ; preds = %0, %3, %6
%9 = phi i8* [ %7, %6 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), %3 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), %0 ]
ret i8* %9
}