#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 *, ...);
int wpa_ctrl_command(struct wpa_ctrl *, char *);
int wpa_cli_cmd_password(struct wpa_ctrl *ctrl, int argc, char *argv[]) {
  char cmd[256], *pos, *end;
  int i;
  if (argc < 2) {
    printf("Invalid PASSWORD command: needs two arguments "
           "(network id and password)\n");
    return 0;
  }
  end = cmd + sizeof(cmd);
  pos = cmd;
  pos += snprintf(pos, end - pos, "CTRL-RSP-PASSWORD-%s:%s", argv[0], argv[1]);
  for (i = 2; i < argc; i++)
    pos += snprintf(pos, end - pos, " %s", argv[i]);
  return wpa_ctrl_command(ctrl, cmd);
}


x86 assembly (clang, -O0):
<wpa_cli_cmd_password>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
cmpl   $0x2,-0x14(%rbp)
jge    1168 <wpa_cli_cmd_password+0x38>
lea    0xea9(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1264 <wpa_cli_cmd_password+0x134>
lea    -0x120(%rbp),%rax
add    $0x100,%rax
mov    %rax,-0x130(%rbp)
lea    -0x120(%rbp),%rax
mov    %rax,-0x128(%rbp)
mov    -0x128(%rbp),%rdi
mov    -0x130(%rbp),%rax
mov    -0x128(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
mov    -0x20(%rbp),%rax
mov    (%rax),%rcx
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%r8
lea    0xe8f(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    %eax,%ecx
mov    -0x128(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x128(%rbp)
movl   $0x2,-0x134(%rbp)
mov    -0x134(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1251 <wpa_cli_cmd_password+0x121>
mov    -0x128(%rbp),%rdi
mov    -0x130(%rbp),%rax
mov    -0x128(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
mov    -0x20(%rbp),%rax
movslq -0x134(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
lea    0xe41(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    %eax,%ecx
mov    -0x128(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x128(%rbp)
mov    -0x134(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x134(%rbp)
jmp    11e1 <wpa_cli_cmd_password+0xb1>
mov    -0x10(%rbp),%rdi
lea    -0x120(%rbp),%rsi
call   1050 <wpa_ctrl_command@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wpa_cli_cmd_password>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
cmp    $0x1,%esi
jg     1159 <wpa_cli_cmd_password+0x29>
lea    0xecf(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
jmp    11e3 <wpa_cli_cmd_password+0xb3>
mov    %rdx,%r15
mov    %esi,%r12d
mov    %rdi,0x8(%rsp)
mov    (%rdx),%rcx
mov    0x8(%rdx),%r8
lea    0xe8e(%rip),%rdx
lea    0x10(%rsp),%rdi
mov    $0x100,%esi
xor    %eax,%eax
call   1040 <snprintf@plt>
cmp    $0x2,%r12d
je     11d4 <wpa_cli_cmd_password+0xa4>
lea    0x110(%rsp),%r13
cltq
lea    (%rsp,%rax,1),%rbx
add    $0x10,%rbx
mov    %r12d,%ebp
mov    $0x2,%r14d
lea    0xe6d(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    %r13d,%esi
sub    %ebx,%esi
mov    (%r15,%r14,8),%rcx
mov    %rbx,%rdi
mov    %r12,%rdx
xor    %eax,%eax
call   1040 <snprintf@plt>
cltq
add    %rax,%rbx
add    $0x1,%r14
cmp    %r14,%rbp
jne    11b0 <wpa_cli_cmd_password+0x80>
lea    0x10(%rsp),%rsi
mov    0x8(%rsp),%rdi
call   1050 <wpa_ctrl_command@plt>
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.wpa_ctrl = type { i32 }
@.str = [73 x i8] c"Invalid PASSWORD command: needs two arguments (network id and password)\0A\00"
@.str.1 = [24 x i8] c"CTRL-RSP-PASSWORD-%s:%s\00"
@.str.2 = [4 x i8] c" %s\00"
define i32 @wpa_cli_cmd_password(%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]
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
store %struct.wpa_ctrl* %0, %struct.wpa_ctrl** %5
store i32 %1, i32* %6
store i8** %2, i8*** %7
%12 = load i32, i32* %6
%13 = icmp slt i32 %12, 2
br i1 %13, label %14, label %16
14: ; preds = %3
%15 = call i32 @printf(i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %4
br label %65
16: ; preds = %3
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%18 = getelementptr inbounds i8, i8* %17, i64 256
store i8* %18, i8** %10
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
store i8* %19, i8** %9
%20 = load i8*, i8** %9
%21 = load i8*, i8** %10
%22 = load i8*, i8** %9
%23 = ptrtoint i8* %21 to i64
%24 = ptrtoint i8* %22 to i64
%25 = sub i64 %23, %24
%26 = trunc i64 %25 to i32
%27 = load i8**, i8*** %7
%28 = getelementptr inbounds i8*, i8** %27, i64 0
%29 = load i8*, i8** %28
%30 = load i8**, i8*** %7
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %20, i32 %26, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %29, i8* %32)
%34 = load i8*, i8** %9
%35 = sext i32 %33 to i64
%36 = getelementptr inbounds i8, i8* %34, i64 %35
store i8* %36, i8** %9
store i32 2, i32* %11
br label %37
37: ; preds = %58, %16
%38 = load i32, i32* %11
%39 = load i32, i32* %6
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %61
41: ; preds = %37
%42 = load i8*, i8** %9
%43 = load i8*, i8** %10
%44 = load i8*, i8** %9
%45 = ptrtoint i8* %43 to i64
%46 = ptrtoint i8* %44 to i64
%47 = sub i64 %45, %46
%48 = trunc i64 %47 to i32
%49 = load i8**, i8*** %7
%50 = load i32, i32* %11
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8*, i8** %49, i64 %51
%53 = load i8*, i8** %52
%54 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %42, i32 %48, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %53)
%55 = load i8*, i8** %9
%56 = sext i32 %54 to i64
%57 = getelementptr inbounds i8, i8* %55, i64 %56
store i8* %57, i8** %9
br label %58
58: ; preds = %41
%59 = load i32, i32* %11
%60 = add nsw i32 %59, 1
store i32 %60, i32* %11
br label %37
61: ; preds = %37
%62 = load %struct.wpa_ctrl*, %struct.wpa_ctrl** %5
%63 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%64 = call i32 @wpa_ctrl_command(%struct.wpa_ctrl* %62, i8* %63)
store i32 %64, i32* %4
br label %65
65: ; preds = %61, %14
%66 = load i32, i32* %4
ret i32 %66
}

LLVM IR (-O2):
%struct.wpa_ctrl = type { i32 }
@.str.1 = [24 x i8] c"CTRL-RSP-PASSWORD-%s:%s\00"
@.str.2 = [4 x i8] c" %s\00"
@str = [72 x i8] c"Invalid PASSWORD command: needs two arguments (network id and password)\00"
define i32 @wpa_cli_cmd_password(%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
%6 = icmp slt i32 %1, 2
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([72 x i8], [72 x i8]* @str, i64 0, i64 0))
br label %36
9: ; preds = %3
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 256
%11 = ptrtoint i8* %10 to i64
%12 = load i8*, i8** %2
%13 = getelementptr inbounds i8*, i8** %2, i64 1
%14 = load i8*, i8** %13
%15 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %5, i32 256, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %12, i8* %14)
%16 = icmp eq i32 %1, 2
br i1 %16, label %34, label %17
17: ; preds = %9
%18 = sext i32 %15 to i64
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %18
%20 = zext i32 %1 to i64
br label %21
21: ; preds = %17, %21
%22 = phi i64 [ 2, %17 ], [ %32, %21 ]
%23 = phi i8* [ %19, %17 ], [ %31, %21 ]
%24 = ptrtoint i8* %23 to i64
%25 = sub i64 %11, %24
%26 = trunc i64 %25 to i32
%27 = getelementptr inbounds i8*, i8** %2, i64 %22
%28 = load i8*, i8** %27
%29 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %23, i32 %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %28)
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %23, i64 %30
%32 = add nuw nsw i64 %22, 1
%33 = icmp eq i64 %32, %20
br i1 %33, label %34, label %21
34: ; preds = %21, %9
%35 = call i32 @wpa_ctrl_command(%struct.wpa_ctrl* %0, i8* %5)
br label %36
36: ; preds = %34, %7
%37 = phi i32 [ 0, %7 ], [ %35, %34 ]
ret i32 %37
}