#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 */
struct shell_struct {
  int dummy;
};
struct netif {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
struct netif *netif_default_iface();
void set_iface_address(struct netif *, char *const);
void show_ip(int /*<<< orphan*/, struct netif *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcmp(char const *, char *);
void usage();
void ip_cmd_main(struct shell_struct *s, int argc, char *const argv[]) {
  const char *argv1 = argv[1];
  struct netif *ifp;
  ifp = netif_default_iface();
  if (argc == 1 || (argc == 2 && !strcmp(argv1, "get")))
    return show_ip(stdout, ifp);
  if (argc == 3 && !strcmp(argv1, "set"))
    return set_iface_address(ifp, argv[2]);
  if (argc == 2 && !strcmp(argv1, "help"))
    return usage();
  fprintf(stderr, "Command failed, try \"ip help\".\n");
  usage();
}


x86 assembly (clang, -O0):
<ip_cmd_main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1030 <netif_default_iface@plt>
mov    %rax,-0x28(%rbp)
cmpl   $0x1,-0xc(%rbp)
je     11b7 <ip_cmd_main+0x57>
cmpl   $0x2,-0xc(%rbp)
jne    11ce <ip_cmd_main+0x6e>
mov    -0x20(%rbp),%rdi
lea    0xe57(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    11ce <ip_cmd_main+0x6e>
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rsi
call   1070 <show_ip@plt>
jmp    1252 <ip_cmd_main+0xf2>
cmpl   $0x3,-0xc(%rbp)
jne    1207 <ip_cmd_main+0xa7>
mov    -0x20(%rbp),%rdi
lea    0xe21(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    1207 <ip_cmd_main+0xa7>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rsi
call   1080 <set_iface_address@plt>
jmp    1252 <ip_cmd_main+0xf2>
cmpl   $0x2,-0xc(%rbp)
jne    1236 <ip_cmd_main+0xd6>
mov    -0x20(%rbp),%rdi
lea    0xdec(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    1236 <ip_cmd_main+0xd6>
mov    $0x0,%al
call   1060 <usage@plt>
jmp    1252 <ip_cmd_main+0xf2>
mov    0x2da3(%rip),%rax
mov    (%rax),%edi
lea    0xdc7(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x0,%al
call   1060 <usage@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ip_cmd_main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %esi,%ebp
mov    0x8(%rdx),%r15
xor    %eax,%eax
call   1030 <netif_default_iface@plt>
mov    %rax,%r14
cmp    $0x1,%ebp
je     11b1 <ip_cmd_main+0x51>
cmp    $0x3,%ebp
je     11cc <ip_cmd_main+0x6c>
cmp    $0x2,%ebp
jne    11df <ip_cmd_main+0x7f>
lea    0xe70(%rip),%rsi
mov    %r15,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
je     11b1 <ip_cmd_main+0x51>
lea    0xe65(%rip),%rsi
mov    %r15,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
jne    11df <ip_cmd_main+0x7f>
jmp    11f4 <ip_cmd_main+0x94>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <show_ip@plt>
lea    0xe31(%rip),%rsi
mov    %r15,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
je     1205 <ip_cmd_main+0xa5>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
lea    0xe1e(%rip),%rsi
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <usage@plt>
mov    0x10(%rbx),%rsi
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <set_iface_address@plt>

LLVM IR (-O0):
%struct.shell_struct = type { i32 }
%struct.netif = type { i32 }
@.str = [4 x i8] c"get\00"
@stdout = global i32 0
@.str.1 = [4 x i8] c"set\00"
@.str.2 = [5 x i8] c"help\00"
@stderr = global i32 0
@.str.3 = [32 x i8] c"Command failed, try \22ip help\22.\0A\00"
define void @ip_cmd_main(%struct.shell_struct* %0, i32 %1, i8** %2) {
%4 = alloca %struct.shell_struct*
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8*
%8 = alloca %struct.netif*
store %struct.shell_struct* %0, %struct.shell_struct** %4
store i32 %1, i32* %5
store i8** %2, i8*** %6
%9 = load i8**, i8*** %6
%10 = getelementptr inbounds i8*, i8** %9, i64 1
%11 = load i8*, i8** %10
store i8* %11, i8** %7
%12 = call %struct.netif* (...) @netif_default_iface()
store %struct.netif* %12, %struct.netif** %8
%13 = load i32, i32* %5
%14 = icmp eq i32 %13, 1
br i1 %14, label %22, label %15
15: ; preds = %3
%16 = load i32, i32* %5
%17 = icmp eq i32 %16, 2
br i1 %17, label %18, label %25
18: ; preds = %15
%19 = load i8*, i8** %7
%20 = call i32 @strcmp(i8* %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%21 = icmp ne i32 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %18, %3
%23 = load i32, i32* @stdout
%24 = load %struct.netif*, %struct.netif** %8
br label %48
25: ; preds = %18, %15
%26 = load i32, i32* %5
%27 = icmp eq i32 %26, 3
br i1 %27, label %28, label %37
28: ; preds = %25
%29 = load i8*, i8** %7
%30 = call i32 @strcmp(i8* %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%31 = icmp ne i32 %30, 0
br i1 %31, label %37, label %32
32: ; preds = %28
%33 = load %struct.netif*, %struct.netif** %8
%34 = load i8**, i8*** %6
%35 = getelementptr inbounds i8*, i8** %34, i64 2
%36 = load i8*, i8** %35
br label %48
37: ; preds = %28, %25
%38 = load i32, i32* %5
%39 = icmp eq i32 %38, 2
br i1 %39, label %40, label %45
40: ; preds = %37
%41 = load i8*, i8** %7
%42 = call i32 @strcmp(i8* %41, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%43 = icmp ne i32 %42, 0
br i1 %43, label %45, label %44
44: ; preds = %40
br label %48
45: ; preds = %40, %37
%46 = load i32, i32* @stderr
%47 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
br label %48
48: ; preds = %45, %44, %32, %22
ret void
}

LLVM IR (-O2):
%struct.shell_struct = type { i32 }
%struct.netif = type { i32 }
@.str = [4 x i8] c"get\00"
@stdout = global i32 0
@.str.1 = [4 x i8] c"set\00"
@.str.2 = [5 x i8] c"help\00"
@stderr = global i32 0
@.str.3 = [32 x i8] c"Command failed, try \22ip help\22.\0A\00"
define void @ip_cmd_main(%struct.shell_struct* nocapture readnone %0, i32 %1, i8** nocapture %2) {
%4 = getelementptr inbounds i8*, i8** %2, i64 1
%5 = load i8*, i8** %4
%6 = tail call %struct.netif* (...) @netif_default_iface()
switch i32 %1, label %22 [
i32 1, label %10
i32 2, label %7
i32 3, label %12
]
7: ; preds = %3
%8 = tail call i32 @strcmp(i8* dereferenceable(1) %5, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %18
10: ; preds = %3, %7
%11 = load i32, i32* @stdout
tail call void @show_ip(i32 %11, %struct.netif* %6)
br label %25
12: ; preds = %3
%13 = tail call i32 @strcmp(i8* dereferenceable(1) %5, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %22
15: ; preds = %12
%16 = getelementptr inbounds i8*, i8** %2, i64 2
%17 = load i8*, i8** %16
tail call void @set_iface_address(%struct.netif* %6, i8* %17)
br label %25
18: ; preds = %7
%19 = tail call i32 @strcmp(i8* dereferenceable(1) %5, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %18
tail call void (...) @usage()
br label %25
22: ; preds = %3, %12, %18
%23 = load i32, i32* @stderr
%24 = tail call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
tail call void (...) @usage()
br label %25
25: ; preds = %22, %21, %15, %10
ret void
}