#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 */

/* Variables and functions */
int construct_vap(char *, int, int, int);
int /*<<< orphan*/ nvram_get_ap_ssid(int, int, char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int /*<<< orphan*/ system(char *);
int set_ssid(int radio, int mode, int vap_id) {
  char ssid[128] = {0};
  char vap_name[8] = {0};
  int ret;
  char cmd[256] = {0};
  nvram_get_ap_ssid(radio, vap_id, ssid, 1);
  ret = construct_vap(vap_name, radio, vap_id, mode);
  if (-1 == ret) {
    printf("ERRO:Construc VAP failure!\n");
    return -1;
  }
  sprintf(cmd, "iwconfig %s essid \"%s\"", vap_name, ssid);
  do {
    printf("\033[1;33;40m");
    printf(cmd);
    printf("\033[0m");
    printf("\n");
    system(cmd);
  } while (0);
  return 0;
}


x86 assembly (clang, -O0):
<set_ssid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1a0,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1070 <memset@plt>
lea    -0x98(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1070 <memset@plt>
lea    -0x1a0(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1070 <memset@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%esi
lea    -0x90(%rbp),%rdx
mov    $0x1,%ecx
call   1060 <nvram_get_ap_ssid@plt>
lea    -0x98(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0xc(%rbp),%ecx
call   1030 <construct_vap@plt>
mov    %eax,-0x9c(%rbp)
mov    $0xffffffff,%eax
cmp    -0x9c(%rbp),%eax
jne    1208 <set_ssid+0xa8>
lea    0xe09(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    126c <set_ssid+0x10c>
lea    -0x1a0(%rbp),%rdi
lea    -0x98(%rbp),%rdx
lea    -0x90(%rbp),%rcx
lea    0xdf8(%rip),%rsi
call   1080 <sprintf@plt>
lea    0xe03(%rip),%rdi
call   1050 <printf@plt>
lea    -0x1a0(%rbp),%rdi
call   1050 <printf@plt>
lea    0xdf6(%rip),%rdi
call   1050 <printf@plt>
lea    0xdc6(%rip),%rdi
call   1050 <printf@plt>
lea    -0x1a0(%rbp),%rdi
call   1040 <system@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_ssid>:
push   %rbp
push   %r14
push   %rbx
sub    $0x190,%rsp
mov    %edx,%ebp
mov    %esi,%r14d
mov    %edi,%ebx
xorps  %xmm0,%xmm0
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
movaps %xmm0,0x180(%rsp)
movaps %xmm0,0x170(%rsp)
movaps %xmm0,0x160(%rsp)
movaps %xmm0,0x150(%rsp)
movaps %xmm0,0x140(%rsp)
movaps %xmm0,0x130(%rsp)
movaps %xmm0,0x120(%rsp)
movaps %xmm0,0x110(%rsp)
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
lea    0x10(%rsp),%rdx
mov    %ebp,%esi
mov    $0x1,%ecx
call   1080 <nvram_get_ap_ssid@plt>
lea    0x8(%rsp),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %r14d,%ecx
call   1040 <construct_vap@plt>
cmp    $0xffffffff,%eax
je     12b7 <set_ssid+0x147>
lea    0xd99(%rip),%rsi
lea    0x90(%rsp),%rbx
lea    0x8(%rsp),%rdx
lea    0x10(%rsp),%rcx
mov    %rbx,%rdi
call   1090 <sprintf@plt>
lea    0xd8f(%rip),%rdi
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1070 <printf@plt>
lea    0xd86(%rip),%rdi
call   1070 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1060 <system@plt>
xor    %eax,%eax
jmp    12c8 <set_ssid+0x158>
lea    0xd69(%rip),%rdi
call   1050 <puts@plt>
mov    $0xffffffff,%eax
add    $0x190,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [28 x i8] c"ERRO:Construc VAP failure!\0A\00"
@.str.1 = [23 x i8] c"iwconfig %s essid \22%s\22\00"
@.str.2 = [11 x i8] c"\1B[1;33;40m\00"
@.str.3 = [5 x i8] c"\1B[0m\00"
@.str.4 = [2 x i8] c"\0A\00"
define i32 @set_ssid(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [128 x i8]
%9 = alloca [8 x i8]
%10 = alloca i32
%11 = alloca [256 x i8]
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%12 = bitcast [128 x i8]* %8 to i8*
%13 = bitcast [8 x i8]* %9 to i8*
%14 = bitcast [256 x i8]* %11 to i8*
%15 = load i32, i32* %5
%16 = load i32, i32* %7
%17 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%18 = call i32 @nvram_get_ap_ssid(i32 %15, i32 %16, i8* %17, i32 1)
%19 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 0
%20 = load i32, i32* %5
%21 = load i32, i32* %7
%22 = load i32, i32* %6
%23 = call i32 @construct_vap(i8* %19, i32 %20, i32 %21, i32 %22)
store i32 %23, i32* %10
%24 = load i32, i32* %10
%25 = icmp eq i32 -1, %24
br i1 %25, label %26, label %28
26: ; preds = %3
%27 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %42
28: ; preds = %3
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%30 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 0
%31 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%32 = call i32 @sprintf(i8* %29, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %30, i8* %31)
br label %33
33: ; preds = %28
%34 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%35 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%36 = call i32 @printf(i8* %35)
%37 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%38 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%39 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%40 = call i32 @system(i8* %39)
br label %41
41: ; preds = %33
store i32 0, i32* %4
br label %42
42: ; preds = %41, %26
%43 = load i32, i32* %4
ret i32 %43
}

LLVM IR (-O2):
@.str.1 = [23 x i8] c"iwconfig %s essid \22%s\22\00"
@.str.2 = [11 x i8] c"\1B[1;33;40m\00"
@.str.3 = [5 x i8] c"\1B[0m\00"
@str = [27 x i8] c"ERRO:Construc VAP failure!\00"
define i32 @set_ssid(i32 %0, i32 %1, i32 %2) {
%4 = alloca [128 x i8]
%5 = alloca i64
%6 = alloca [256 x i8]
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%8 = bitcast i64* %5 to i8*
store i64 0, i64* %5
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%10 = call i32 @nvram_get_ap_ssid(i32 %0, i32 %2, i8* %7, i32 1)
%11 = call i32 @construct_vap(i8* %8, i32 %0, i32 %2, i32 %1)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %3
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
br label %22
15: ; preds = %3
%16 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %8, i8* %7)
%17 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 @printf(i8* %9)
%19 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%20 = call i32 @putchar(i32 10)
%21 = call i32 @system(i8* %9)
br label %22
22: ; preds = %15, %13
%23 = phi i32 [ -1, %13 ], [ 0, %15 ]
ret i32 %23
}