#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 wpa_ctrl {
  int dummy;
};
typedef int /*<<< orphan*/ cmd;

/* Variables and functions */
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, char *);
scalar_t__ strcmp(char const *, char *);
int wpa_ctrl_command(struct wpa_ctrl *, char *);
int wpa_cli_cmd_get_capability(struct wpa_ctrl *ctrl, int argc,
                               const char *argv[]) {
  char cmd[64];
  if (argc < 1 || argc > 2) {
    printf("Invalid GET_CAPABILITY command: need either one or "
           "two arguments\n");
    return -1;
  }
  if ((argc == 2) && strcmp(argv[1], "strict") != 0) {
    printf("Invalid GET_CAPABILITY command: second argument, "
           "if any, must be 'strict'\n");
    return -1;
  }
  snprintf(cmd, sizeof(cmd), "GET_CAPABILITY %s%s", argv[0],
           (argc == 2) ? " strict" : "");
  cmd[sizeof(cmd) - 1] = '\0';
  return wpa_ctrl_command(ctrl, cmd);
}


x86 assembly (clang, -O0):
<wpa_cli_cmd_get_capability>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
cmpl   $0x1,-0x14(%rbp)
jl     1167 <wpa_cli_cmd_get_capability+0x27>
cmpl   $0x2,-0x14(%rbp)
jle    117f <wpa_cli_cmd_get_capability+0x3f>
lea    0xe92(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1207 <wpa_cli_cmd_get_capability+0xc7>
cmpl   $0x2,-0x14(%rbp)
jne    11bf <wpa_cli_cmd_get_capability+0x7f>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xf0a(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     11bf <wpa_cli_cmd_get_capability+0x7f>
lea    0xe94(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1207 <wpa_cli_cmd_get_capability+0xc7>
lea    -0x60(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%rcx
mov    -0x14(%rbp),%edx
lea    0xeb8(%rip),%r8
lea    0xec6(%rip),%rax
cmp    $0x2,%edx
cmove  %rax,%r8
mov    $0x40,%esi
lea    0xe9f(%rip),%rdx
call   1040 <snprintf@plt>
movb   $0x0,-0x21(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x60(%rbp),%rsi
call   1060 <wpa_ctrl_command@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wpa_cli_cmd_get_capability>:
push   %r14
push   %rbx
sub    $0x48,%rsp
lea    -0x3(%rsi),%eax
cmp    $0xfffffffd,%eax
ja     1158 <wpa_cli_cmd_get_capability+0x18>
lea    0xf10(%rip),%rdi
jmp    117f <wpa_cli_cmd_get_capability+0x3f>
mov    %rdx,%rbx
mov    %rdi,%r14
cmp    $0x2,%esi
jne    118b <wpa_cli_cmd_get_capability+0x4b>
mov    0x8(%rbx),%rdi
lea    0xea7(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1194 <wpa_cli_cmd_get_capability+0x54>
lea    0xe9d(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
jmp    11c5 <wpa_cli_cmd_get_capability+0x85>
lea    0xed3(%rip),%r8
jmp    119b <wpa_cli_cmd_get_capability+0x5b>
lea    0xe79(%rip),%r8
mov    (%rbx),%rcx
lea    0xe5b(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x40,%esi
call   1040 <snprintf@plt>
movb   $0x0,0x3f(%rsp)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <wpa_ctrl_command@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.wpa_ctrl = type { i32 }
@.str = [66 x i8] c"Invalid GET_CAPABILITY command: need either one or two arguments\0A\00"
@.str.1 = [7 x i8] c"strict\00"
@.str.2 = [75 x i8] c"Invalid GET_CAPABILITY command: second argument, if any, must be 'strict'\0A\00"
@.str.3 = [20 x i8] c"GET_CAPABILITY %s%s\00"
@.str.4 = [8 x i8] c" strict\00"
@.str.5 = [1 x i8] zeroinitializer
define i32 @wpa_cli_cmd_get_capability(%struct.wpa_ctrl* %0, i32 %1, i8** %2) {
%4 = alloca i32
%5 = alloca %struct.wpa_ctrl*
%6 = alloca i32
%7 = alloca i8**
%8 = alloca [64 x i8]
store %struct.wpa_ctrl* %0, %struct.wpa_ctrl** %5
store i32 %1, i32* %6
store i8** %2, i8*** %7
%9 = load i32, i32* %6
%10 = icmp slt i32 %9, 1
br i1 %10, label %14, label %11
11: ; preds = %3
%12 = load i32, i32* %6
%13 = icmp sgt i32 %12, 2
br i1 %13, label %14, label %16
14: ; preds = %11, %3
%15 = call i32 @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %41
16: ; preds = %11
%17 = load i32, i32* %6
%18 = icmp eq i32 %17, 2
br i1 %18, label %19, label %27
19: ; preds = %16
%20 = load i8**, i8*** %7
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i64 @strcmp(i8* %22, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %19
%26 = call i32 @printf(i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %4
br label %41
27: ; preds = %19, %16
%28 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%29 = load i8**, i8*** %7
%30 = getelementptr inbounds i8*, i8** %29, i64 0
%31 = load i8*, i8** %30
%32 = load i32, i32* %6
%33 = icmp eq i32 %32, 2
%34 = zext i1 %33 to i64
%35 = select i1 %33, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0)
%36 = call i32 @snprintf(i8* %28, i32 64, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %31, i8* %35)
%37 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 63
store i8 0, i8* %37
%38 = load %struct.wpa_ctrl*, %struct.wpa_ctrl** %5
%39 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%40 = call i32 @wpa_ctrl_command(%struct.wpa_ctrl* %38, i8* %39)
store i32 %40, i32* %4
br label %41
41: ; preds = %27, %25, %14
%42 = load i32, i32* %4
ret i32 %42
}

LLVM IR (-O2):
%struct.wpa_ctrl = type { i32 }
@.str.1 = [7 x i8] c"strict\00"
@.str.3 = [20 x i8] c"GET_CAPABILITY %s%s\00"
@.str.4 = [8 x i8] c" strict\00"
@.str.5 = [1 x i8] zeroinitializer
@str = [74 x i8] c"Invalid GET_CAPABILITY command: second argument, if any, must be 'strict'\00"
@str.6 = [65 x i8] c"Invalid GET_CAPABILITY command: need either one or two arguments\00"
define i32 @wpa_cli_cmd_get_capability(%struct.wpa_ctrl* %0, i32 %1, i8** nocapture %2) {
%4 = alloca [64 x i8]
%5 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%6 = add i32 %1, -3
%7 = icmp ult i32 %6, -2
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @str.6, i64 0, i64 0))
br label %25
10: ; preds = %3
%11 = icmp eq i32 %1, 2
br i1 %11, label %12, label %19
12: ; preds = %10
%13 = getelementptr inbounds i8*, i8** %2, i64 1
%14 = load i8*, i8** %13
%15 = tail call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %12
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([74 x i8], [74 x i8]* @str, i64 0, i64 0))
br label %25
19: ; preds = %12, %10
%20 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), %12 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0), %10 ]
%21 = load i8*, i8** %2
%22 = call i32 @snprintf(i8* %5, i32 64, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %21, i8* %20)
%23 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 63
store i8 0, i8* %23
%24 = call i32 @wpa_ctrl_command(%struct.wpa_ctrl* %0, i8* %5)
br label %25
25: ; preds = %19, %17, %8
%26 = phi i32 [ -1, %8 ], [ -1, %17 ], [ %24, %19 ]
ret i32 %26
}