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


x86 assembly (clang, -O0):
<wpa_cli_cmd_new_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_new_password+0x38>
lea    0xea9(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1304 <wpa_cli_cmd_new_password+0x1d4>
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    0xe93(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    %eax,-0x138(%rbp)
cmpl   $0x0,-0x138(%rbp)
jl     11f5 <wpa_cli_cmd_new_password+0xc5>
movslq -0x138(%rbp),%rax
mov    -0x130(%rbp),%rcx
mov    -0x128(%rbp),%rdx
sub    %rdx,%rcx
cmp    %rcx,%rax
jl     120d <wpa_cli_cmd_new_password+0xdd>
lea    0xe6d(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1304 <wpa_cli_cmd_new_password+0x1d4>
mov    -0x138(%rbp),%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    12f1 <wpa_cli_cmd_new_password+0x1c1>
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    0xe19(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    %eax,-0x138(%rbp)
cmpl   $0x0,-0x138(%rbp)
jl     12ab <wpa_cli_cmd_new_password+0x17b>
movslq -0x138(%rbp),%rax
mov    -0x130(%rbp),%rcx
mov    -0x128(%rbp),%rdx
sub    %rdx,%rcx
cmp    %rcx,%rax
jl     12c3 <wpa_cli_cmd_new_password+0x193>
lea    0xdb7(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1304 <wpa_cli_cmd_new_password+0x1d4>
mov    -0x138(%rbp),%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    1231 <wpa_cli_cmd_new_password+0x101>
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_new_password>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
cmp    $0x1,%esi
jg     114f <wpa_cli_cmd_new_password+0x1f>
lea    0xef2(%rip),%rdi
jmp    1184 <wpa_cli_cmd_new_password+0x54>
mov    %rdx,%r15
mov    %esi,%ebp
mov    %rdi,%rbx
mov    (%rdx),%rcx
mov    0x8(%rdx),%r8
lea    0xe9b(%rip),%rdx
lea    0x10(%rsp),%rdi
mov    $0x100,%esi
xor    %eax,%eax
call   1040 <snprintf@plt>
cmp    $0x100,%eax
jb     11a0 <wpa_cli_cmd_new_password+0x70>
lea    0xe9c(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,0x8(%rsp)
cmp    $0x3,%ebp
jb     1205 <wpa_cli_cmd_new_password+0xd5>
mov    %eax,%eax
lea    (%rsp,%rax,1),%rbx
add    $0x10,%rbx
mov    %ebp,%r13d
mov    $0x2,%r14d
lea    0xe58(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0x110(%rsp),%rbp
sub    %rbx,%rbp
mov    (%r15,%r14,8),%rcx
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r12,%rdx
xor    %eax,%eax
call   1040 <snprintf@plt>
test   %eax,%eax
js     117d <wpa_cli_cmd_new_password+0x4d>
mov    %eax,%eax
cmp    %rax,%rbp
jle    117d <wpa_cli_cmd_new_password+0x4d>
add    %rax,%rbx
add    $0x1,%r14
cmp    %r14,%r13
jne    11d0 <wpa_cli_cmd_new_password+0xa0>
lea    0x10(%rsp),%rsi
mov    0x8(%rsp),%rdi
call   1050 <wpa_ctrl_command@plt>
jmp    118e <wpa_cli_cmd_new_password+0x5e>

LLVM IR (-O0):
%struct.wpa_ctrl = type { i32 }
@.str = [77 x i8] c"Invalid NEW_PASSWORD command: needs two arguments (network id and password)\0A\00"
@.str.1 = [28 x i8] c"CTRL-RSP-NEW_PASSWORD-%s:%s\00"
@.str.2 = [32 x i8] c"Too long NEW_PASSWORD command.\0A\00"
@.str.3 = [4 x i8] c" %s\00"
define i32 @wpa_cli_cmd_new_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
%12 = alloca i32
store %struct.wpa_ctrl* %0, %struct.wpa_ctrl** %5
store i32 %1, i32* %6
store i8** %2, i8*** %7
%13 = load i32, i32* %6
%14 = icmp slt i32 %13, 2
br i1 %14, label %15, label %17
15: ; preds = %3
%16 = call i32 @printf(i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %96
17: ; preds = %3
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%19 = getelementptr inbounds i8, i8* %18, i64 256
store i8* %19, i8** %10
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
store i8* %20, i8** %9
%21 = load i8*, i8** %9
%22 = load i8*, i8** %10
%23 = load i8*, i8** %9
%24 = ptrtoint i8* %22 to i64
%25 = ptrtoint i8* %23 to i64
%26 = sub i64 %24, %25
%27 = trunc i64 %26 to i32
%28 = load i8**, i8*** %7
%29 = getelementptr inbounds i8*, i8** %28, i64 0
%30 = load i8*, i8** %29
%31 = load i8**, i8*** %7
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %21, i32 %27, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %30, i8* %33)
store i32 %34, i32* %12
%35 = load i32, i32* %12
%36 = icmp slt i32 %35, 0
br i1 %36, label %46, label %37
37: ; preds = %17
%38 = load i32, i32* %12
%39 = sext i32 %38 to i64
%40 = load i8*, i8** %10
%41 = load i8*, i8** %9
%42 = ptrtoint i8* %40 to i64
%43 = ptrtoint i8* %41 to i64
%44 = sub i64 %42, %43
%45 = icmp sge i64 %39, %44
br i1 %45, label %46, label %48
46: ; preds = %37, %17
%47 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %4
br label %96
48: ; preds = %37
%49 = load i32, i32* %12
%50 = load i8*, i8** %9
%51 = sext i32 %49 to i64
%52 = getelementptr inbounds i8, i8* %50, i64 %51
store i8* %52, i8** %9
store i32 2, i32* %11
br label %53
53: ; preds = %89, %48
%54 = load i32, i32* %11
%55 = load i32, i32* %6
%56 = icmp slt i32 %54, %55
br i1 %56, label %57, label %92
57: ; preds = %53
%58 = load i8*, i8** %9
%59 = load i8*, i8** %10
%60 = load i8*, i8** %9
%61 = ptrtoint i8* %59 to i64
%62 = ptrtoint i8* %60 to i64
%63 = sub i64 %61, %62
%64 = trunc i64 %63 to i32
%65 = load i8**, i8*** %7
%66 = load i32, i32* %11
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i8*, i8** %65, i64 %67
%69 = load i8*, i8** %68
%70 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %58, i32 %64, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %69)
store i32 %70, i32* %12
%71 = load i32, i32* %12
%72 = icmp slt i32 %71, 0
br i1 %72, label %82, label %73
73: ; preds = %57
%74 = load i32, i32* %12
%75 = sext i32 %74 to i64
%76 = load i8*, i8** %10
%77 = load i8*, i8** %9
%78 = ptrtoint i8* %76 to i64
%79 = ptrtoint i8* %77 to i64
%80 = sub i64 %78, %79
%81 = icmp sge i64 %75, %80
br i1 %81, label %82, label %84
82: ; preds = %73, %57
%83 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %4
br label %96
84: ; preds = %73
%85 = load i32, i32* %12
%86 = load i8*, i8** %9
%87 = sext i32 %85 to i64
%88 = getelementptr inbounds i8, i8* %86, i64 %87
store i8* %88, i8** %9
br label %89
89: ; preds = %84
%90 = load i32, i32* %11
%91 = add nsw i32 %90, 1
store i32 %91, i32* %11
br label %53
92: ; preds = %53
%93 = load %struct.wpa_ctrl*, %struct.wpa_ctrl** %5
%94 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%95 = call i32 @wpa_ctrl_command(%struct.wpa_ctrl* %93, i8* %94)
store i32 %95, i32* %4
br label %96
96: ; preds = %92, %82, %46, %15
%97 = load i32, i32* %4
ret i32 %97
}

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