#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 *);
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);
  }
  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    11d0 <main+0x80>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1070 <fw_printenv@plt>
mov    0x2e0a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    124c <main+0xfc>
mov    -0x20(%rbp),%rdi
lea    0xe31(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1222 <main+0xd2>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <fw_setenv@plt>
cmp    $0x0,%rax
je     1211 <main+0xc1>
mov    0x2dd1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    124c <main+0xfc>
mov    0x2db8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    124c <main+0xfc>
jmp    1227 <main+0xd7>
mov    0x2db2(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xddb(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d91(%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     11ce <main+0x7e>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
lea    0xe66(%rip),%rsi
mov    %rbp,%rdx
call   1060 <fprintf@plt>
jmp    11e7 <main+0x97>
mov    %r14d,%edi
mov    %r15,%rsi
call   1070 <fw_printenv@plt>
mov    0x2e04(%rip),%rax
jmp    11ee <main+0x9e>
mov    %r14d,%edi
mov    %r15,%rsi
call   1030 <fw_setenv@plt>
test   %rax,%rax
jne    11e7 <main+0x97>
mov    0x2deb(%rip),%rax
jmp    11ee <main+0x9e>
mov    0x2dea(%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
@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 %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 %44
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 %44
36: ; preds = %29
%37 = load i32, i32* @EXIT_SUCCESS
store i32 %37, i32* %3
br label %44
38: ; preds = %25
br label %39
39: ; preds = %38
%40 = load i32, i32* @stderr
%41 = load i8*, i8** %7
%42 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str.2, i64 0, i64 0), i8* %41)
%43 = load i32, i32* @EXIT_FAILURE
store i32 %43, i32* %3
br label %44
44: ; preds = %39, %36, %34, %20
%45 = load i32, i32* %3
ret i32 %45
}

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
@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 %12
10: ; preds = %2
%11 = tail call i32 @fw_printenv(i32 %0, i8** %1)
br label %22
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 %22
19: ; preds = %12
%20 = load i32, i32* @stderr
%21 = tail call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str.2, i64 0, i64 0), i8* %7)
br label %22
22: ; preds = %15, %19, %10
%23 = phi i32* [ @EXIT_SUCCESS, %10 ], [ @EXIT_FAILURE, %19 ], [ %18, %15 ]
%24 = load i32, i32* %23
ret i32 %24
}