#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 snprintf(char *, int, char *, char *, char *);
int /*<<< orphan*/ wpa_cli_show_variables();
int wpa_ctrl_command(struct wpa_ctrl *, char *);
int wpa_cli_cmd_set(struct wpa_ctrl *ctrl, int argc, char *argv[]) {
  char cmd[256];
  if (argc == 0) {
    wpa_cli_show_variables();
    return 0;
  }
  if (argc != 2) {
    printf("Invalid SET command: needs two arguments (variable "
           "name and value)\n");
    return 0;
  }
  if (snprintf(cmd, sizeof(cmd), "SET %s %s", argv[0], argv[1]) >=
      sizeof(cmd) - 1) {
    printf("Too long SET command.\n");
    return 0;
  }
  return wpa_ctrl_command(ctrl, cmd);
}


x86 assembly (clang, -O0):
<wpa_cli_cmd_set>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1173 <wpa_cli_cmd_set+0x33>
mov    $0x0,%al
call   1050 <wpa_cli_show_variables@plt>
movl   $0x0,-0x4(%rbp)
jmp    11f5 <wpa_cli_cmd_set+0xb5>
cmpl   $0x2,-0x14(%rbp)
je     1195 <wpa_cli_cmd_set+0x55>
lea    0xe7c(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11f5 <wpa_cli_cmd_set+0xb5>
lea    -0x120(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%rcx
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%r8
mov    $0x100,%esi
lea    0xe8d(%rip),%rdx
call   1040 <snprintf@plt>
cltq
cmp    $0xff,%rax
jb     11e2 <wpa_cli_cmd_set+0xa2>
lea    0xe7d(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11f5 <wpa_cli_cmd_set+0xb5>
mov    -0x10(%rbp),%rdi
lea    -0x120(%rbp),%rsi
call   1060 <wpa_ctrl_command@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wpa_cli_cmd_set>:
push   %rbx
sub    $0x100,%rsp
cmp    $0x2,%esi
je     115c <wpa_cli_cmd_set+0x1c>
test   %esi,%esi
jne    118a <wpa_cli_cmd_set+0x4a>
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <wpa_cli_show_variables@plt>
jmp    11a7 <wpa_cli_cmd_set+0x67>
mov    %rdi,%rbx
mov    (%rdx),%rcx
mov    0x8(%rdx),%r8
lea    0xe93(%rip),%rdx
mov    %rsp,%rdi
mov    $0x100,%esi
call   1040 <snprintf@plt>
cmp    $0xff,%eax
jb     119a <wpa_cli_cmd_set+0x5a>
lea    0xe82(%rip),%rdi
jmp    1191 <wpa_cli_cmd_set+0x51>
lea    0xe8f(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
jmp    11a7 <wpa_cli_cmd_set+0x67>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1060 <wpa_ctrl_command@plt>
mov    %eax,%ebx
mov    %ebx,%eax
add    $0x100,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.wpa_ctrl = type { i32 }
@.str = [68 x i8] c"Invalid SET command: needs two arguments (variable name and value)\0A\00"
@.str.1 = [10 x i8] c"SET %s %s\00"
@.str.2 = [23 x i8] c"Too long SET command.\0A\00"
define i32 @wpa_cli_cmd_set(%struct.wpa_ctrl* %0, i32 %1, i8** %2) {
%4 = alloca i32
%5 = alloca %struct.wpa_ctrl*
%6 = alloca i32
%7 = alloca i8**
%8 = alloca [256 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 eq i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %3
%12 = call i32 (...) @wpa_cli_show_variables()
store i32 0, i32* %4
br label %35
13: ; preds = %3
%14 = load i32, i32* %6
%15 = icmp ne i32 %14, 2
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %4
br label %35
18: ; preds = %13
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%20 = load i8**, i8*** %7
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = load i8**, i8*** %7
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @snprintf(i8* %19, i32 256, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %22, i8* %25)
%27 = sext i32 %26 to i64
%28 = icmp uge i64 %27, 255
br i1 %28, label %29, label %31
29: ; preds = %18
%30 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %4
br label %35
31: ; preds = %18
%32 = load %struct.wpa_ctrl*, %struct.wpa_ctrl** %5
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%34 = call i32 @wpa_ctrl_command(%struct.wpa_ctrl* %32, i8* %33)
store i32 %34, i32* %4
br label %35
35: ; preds = %31, %29, %16, %11
%36 = load i32, i32* %4
ret i32 %36
}

LLVM IR (-O2):
%struct.wpa_ctrl = type { i32 }
@.str.1 = [10 x i8] c"SET %s %s\00"
@str = [22 x i8] c"Too long SET command.\00"
@str.3 = [67 x i8] c"Invalid SET command: needs two arguments (variable name and value)\00"
define i32 @wpa_cli_cmd_set(%struct.wpa_ctrl* %0, i32 %1, i8** nocapture %2) {
%4 = alloca [256 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
switch i32 %1, label %8 [
i32 0, label %6
i32 2, label %10
]
6: ; preds = %3
%7 = tail call i32 (...) @wpa_cli_show_variables()
br label %20
8: ; preds = %3
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([67 x i8], [67 x i8]* @str.3, i64 0, i64 0))
br label %20
10: ; preds = %3
%11 = load i8*, i8** %2
%12 = getelementptr inbounds i8*, i8** %2, i64 1
%13 = load i8*, i8** %12
%14 = call i32 @snprintf(i8* %5, i32 256, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %11, i8* %13)
%15 = icmp ugt i32 %14, 254
br i1 %15, label %16, label %18
16: ; preds = %10
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
br label %20
18: ; preds = %10
%19 = call i32 @wpa_ctrl_command(%struct.wpa_ctrl* %0, i8* %5)
br label %20
20: ; preds = %18, %16, %8, %6
%21 = phi i32 [ 0, %6 ], [ 0, %8 ], [ 0, %16 ], [ %19, %18 ]
ret i32 %21
}