#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 */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ fw_loadenv(int, char **);
int /*<<< orphan*/ fw_printenv(int, char **);
scalar_t__ fw_setenv(int, char **);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
char *strrchr(char *, char);
int main(int argc, char *argv[]) {
  char *p;
  char *cmdname = *argv;
  if ((p = strrchr(cmdname, '/')) != NULL) {
    cmdname = p + 1;
  }
  if (strcmp(cmdname, "fw_printenv") == 0) {
    fw_printenv(argc, argv);
    return (EXIT_SUCCESS);
  } else if (strcmp(cmdname, "fw_setenv") == 0) {
    if (fw_setenv(argc, argv) != 0)
      return (EXIT_FAILURE);
    return (EXIT_SUCCESS);
  } else if (strcmp(cmdname, "fw_loadenv") == 0) {
    if (fw_loadenv(argc, argv) != 0)
      return (EXIT_FAILURE);
    return (EXIT_SUCCESS);
  }
  fprintf(stderr,
          "Identity crisis - may be called as `"
          "fw_printenv"
          "' or as `"
          "fw_setenv"
          "' but not as `%s'\n",
          cmdname);
  return (EXIT_FAILURE);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11a9 <main+0x49>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe4c(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11e0 <main+0x80>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1080 <fw_printenv@plt>
mov    0x2dfa(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12b3 <main+0x153>
mov    -0x20(%rbp),%rdi
lea    0xe21(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1232 <main+0xd2>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <fw_setenv@plt>
cmp    $0x0,%rax
je     1221 <main+0xc1>
mov    0x2dc1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12b3 <main+0x153>
mov    0x2da8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12b3 <main+0x153>
mov    -0x20(%rbp),%rdi
lea    0xdd9(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1284 <main+0x124>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <fw_loadenv@plt>
cmp    $0x0,%rax
je     1273 <main+0x113>
mov    0x2d6f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12b3 <main+0x153>
mov    0x2d56(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12b3 <main+0x153>
jmp    1289 <main+0x129>
jmp    128e <main+0x12e>
mov    0x2d4b(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xd7f(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2d2a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,%r14d
mov    (%rsi),%rbx
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
lea    0x1(%rax),%rbp
test   %rax,%rax
cmove  %rbx,%rbp
lea    0xe71(%rip),%rsi
mov    %rbp,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11de <main+0x7e>
lea    0xe69(%rip),%rsi
mov    %rbp,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11f2 <main+0x92>
lea    0xe5f(%rip),%rsi
mov    %rbp,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     120b <main+0xab>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
lea    0xe4d(%rip),%rsi
mov    %rbp,%rdx
call   1070 <fprintf@plt>
jmp    121b <main+0xbb>
mov    %r14d,%edi
mov    %r15,%rsi
call   1080 <fw_printenv@plt>
mov    0x2de0(%rip),%rax
jmp    1222 <main+0xc2>
mov    %r14d,%edi
mov    %r15,%rsi
call   1040 <fw_setenv@plt>
test   %rax,%rax
jne    121b <main+0xbb>
mov    0x2dc7(%rip),%rax
jmp    1222 <main+0xc2>
mov    %r14d,%edi
mov    %r15,%rsi
call   1030 <fw_loadenv@plt>
test   %rax,%rax
je     1202 <main+0xa2>
mov    0x2db6(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"fw_printenv\00"
@EXIT_SUCCESS = global i32 0
@.str.1 = [10 x i8] c"fw_setenv\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [11 x i8] c"fw_loadenv\00"
@stderr = global i32 0
@.str.3 = [84 x i8] c"Identity crisis - may be called as `fw_printenv' or as `fw_setenv' but not as `%s'\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i8**, i8*** %5
%9 = load i8*, i8** %8
store i8* %9, i8** %7
%10 = load i8*, i8** %7
%11 = call i8* @strrchr(i8* %10, i8 signext 47)
store i8* %11, i8** %6
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i8*, i8** %6
%15 = getelementptr inbounds i8, i8* %14, i64 1
store i8* %15, i8** %7
br label %16
16: ; preds = %13, %2
%17 = load i8*, i8** %7
%18 = call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %16
%21 = load i32, i32* %4
%22 = load i8**, i8*** %5
%23 = call i32 @fw_printenv(i32 %21, i8** %22)
%24 = load i32, i32* @EXIT_SUCCESS
store i32 %24, i32* %3
br label %58
25: ; preds = %16
%26 = load i8*, i8** %7
%27 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %38
29: ; preds = %25
%30 = load i32, i32* %4
%31 = load i8**, i8*** %5
%32 = call i64 @fw_setenv(i32 %30, i8** %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %29
%35 = load i32, i32* @EXIT_FAILURE
store i32 %35, i32* %3
br label %58
36: ; preds = %29
%37 = load i32, i32* @EXIT_SUCCESS
store i32 %37, i32* %3
br label %58
38: ; preds = %25
%39 = load i8*, i8** %7
%40 = call i64 @strcmp(i8* %39, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %51
42: ; preds = %38
%43 = load i32, i32* %4
%44 = load i8**, i8*** %5
%45 = call i64 @fw_loadenv(i32 %43, i8** %44)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %42
%48 = load i32, i32* @EXIT_FAILURE
store i32 %48, i32* %3
br label %58
49: ; preds = %42
%50 = load i32, i32* @EXIT_SUCCESS
store i32 %50, i32* %3
br label %58
51: ; preds = %38
br label %52
52: ; preds = %51
br label %53
53: ; preds = %52
%54 = load i32, i32* @stderr
%55 = load i8*, i8** %7
%56 = call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str.3, i64 0, i64 0), i8* %55)
%57 = load i32, i32* @EXIT_FAILURE
store i32 %57, i32* %3
br label %58
58: ; preds = %53, %49, %47, %36, %34, %20
%59 = load i32, i32* %3
ret i32 %59
}

LLVM IR (-O2):
@.str = [12 x i8] c"fw_printenv\00"
@EXIT_SUCCESS = global i32 0
@.str.1 = [10 x i8] c"fw_setenv\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [11 x i8] c"fw_loadenv\00"
@stderr = global i32 0
@.str.3 = [84 x i8] c"Identity crisis - may be called as `fw_printenv' or as `fw_setenv' but not as `%s'\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = load i8*, i8** %1
%4 = tail call i8* @strrchr(i8* dereferenceable(1) %3, i8 signext 47)
%5 = icmp eq i8* %4, null
%6 = getelementptr inbounds i8, i8* %4, i64 1
%7 = select i1 %5, i8* %3, i8* %6
%8 = tail call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = tail call i32 @fw_printenv(i32 %0, i8** %1)
br label %29
12: ; preds = %2
%13 = tail call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %12
%16 = tail call i64 @fw_setenv(i32 %0, i8** %1)
%17 = icmp eq i64 %16, 0
%18 = select i1 %17, i32* @EXIT_SUCCESS, i32* @EXIT_FAILURE
br label %29
19: ; preds = %12
%20 = tail call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = tail call i64 @fw_loadenv(i32 %0, i8** %1)
%24 = icmp eq i64 %23, 0
%25 = select i1 %24, i32* @EXIT_SUCCESS, i32* @EXIT_FAILURE
br label %29
26: ; preds = %19
%27 = load i32, i32* @stderr
%28 = tail call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str.3, i64 0, i64 0), i8* %7)
br label %29
29: ; preds = %22, %15, %26, %10
%30 = phi i32* [ @EXIT_SUCCESS, %10 ], [ @EXIT_FAILURE, %26 ], [ %18, %15 ], [ %25, %22 ]
%31 = load i32, i32* %30
ret i32 %31
}