#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_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) {
    if (fw_printenv(argc, argv) != 0)
      return (EXIT_FAILURE);
    return (EXIT_SUCCESS);
  } else if (strcmp(cmdname, "fw_setenv") == 0) {
    if (fw_setenv(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   1040 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1199 <main+0x49>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe5c(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11eb <main+0x9b>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1070 <fw_printenv@plt>
cmp    $0x0,%rax
je     11da <main+0x8a>
mov    0x2e08(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1267 <main+0x117>
mov    0x2def(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1267 <main+0x117>
mov    -0x20(%rbp),%rdi
lea    0xe16(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    123d <main+0xed>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <fw_setenv@plt>
cmp    $0x0,%rax
je     122c <main+0xdc>
mov    0x2db6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1267 <main+0x117>
mov    0x2d9d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1267 <main+0x117>
jmp    1242 <main+0xf2>
mov    0x2d97(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xdc0(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d76(%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   1040 <strrchr@plt>
lea    0x1(%rax),%rbp
test   %rax,%rax
cmove  %rbx,%rbp
lea    0xe81(%rip),%rsi
mov    %rbp,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11ba <main+0x6a>
lea    0xe79(%rip),%rsi
mov    %rbp,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11d3 <main+0x83>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
lea    0xe66(%rip),%rsi
mov    %rbp,%rdx
call   1060 <fprintf@plt>
jmp    11e3 <main+0x93>
mov    %r14d,%edi
mov    %r15,%rsi
call   1070 <fw_printenv@plt>
test   %rax,%rax
jne    11e3 <main+0x93>
mov    0x2dff(%rip),%rax
jmp    11ea <main+0x9a>
mov    %r14d,%edi
mov    %r15,%rsi
call   1030 <fw_setenv@plt>
test   %rax,%rax
je     11ca <main+0x7a>
mov    0x2dee(%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_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
@.str.1 = [10 x i8] c"fw_setenv\00"
@stderr = global i32 0
@.str.2 = [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 %29
20: ; preds = %16
%21 = load i32, i32* %4
%22 = load i8**, i8*** %5
%23 = call i64 @fw_printenv(i32 %21, i8** %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %20
%26 = load i32, i32* @EXIT_FAILURE
store i32 %26, i32* %3
br label %48
27: ; preds = %20
%28 = load i32, i32* @EXIT_SUCCESS
store i32 %28, i32* %3
br label %48
29: ; preds = %16
%30 = load i8*, i8** %7
%31 = call i64 @strcmp(i8* %30, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %42
33: ; preds = %29
%34 = load i32, i32* %4
%35 = load i8**, i8*** %5
%36 = call i64 @fw_setenv(i32 %34, i8** %35)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %33
%39 = load i32, i32* @EXIT_FAILURE
store i32 %39, i32* %3
br label %48
40: ; preds = %33
%41 = load i32, i32* @EXIT_SUCCESS
store i32 %41, i32* %3
br label %48
42: ; preds = %29
br label %43
43: ; preds = %42
%44 = load i32, i32* @stderr
%45 = load i8*, i8** %7
%46 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str.2, i64 0, i64 0), i8* %45)
%47 = load i32, i32* @EXIT_FAILURE
store i32 %47, i32* %3
br label %48
48: ; preds = %43, %40, %38, %27, %25
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
@.str = [12 x i8] c"fw_printenv\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
@.str.1 = [10 x i8] c"fw_setenv\00"
@stderr = global i32 0
@.str.2 = [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 %14
10: ; preds = %2
%11 = tail call i64 @fw_printenv(i32 %0, i8** %1)
%12 = icmp eq i64 %11, 0
%13 = select i1 %12, i32* @EXIT_SUCCESS, i32* @EXIT_FAILURE
br label %24
14: ; preds = %2
%15 = tail call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = tail call i64 @fw_setenv(i32 %0, i8** %1)
%19 = icmp eq i64 %18, 0
%20 = select i1 %19, i32* @EXIT_SUCCESS, i32* @EXIT_FAILURE
br label %24
21: ; preds = %14
%22 = load i32, i32* @stderr
%23 = tail call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str.2, i64 0, i64 0), i8* %7)
br label %24
24: ; preds = %17, %10, %21
%25 = phi i32* [ @EXIT_FAILURE, %21 ], [ %13, %10 ], [ %20, %17 ]
%26 = load i32, i32* %25
ret i32 %26
}