#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 /*<<< orphan*/);
int /*<<< orphan*/ nvram_get_ap_dtim(int, int *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, int);
int /*<<< orphan*/ system(char *);
int set_dtim(int radio) {
  char cmd[128] = {0};
  int dtim;
  int ret;
  int vap_num = 8;
  char vap_name[8] = {0};
  int i;
  nvram_get_ap_dtim(radio, &dtim);
  for (i = 0; i < vap_num; i++) {
    ret = construct_vap(vap_name, radio, i, 0);
    if (-1 == ret) {
      printf("ERROR:Construct VAP failure!\n");
      return -1;
    }
    sprintf(cmd, "iwpriv %s dtim_period %d", vap_name, dtim);
    do {
      printf("\033[1;33;40m");
      printf(cmd);
      printf("\033[0m");
      printf("\n");
      system(cmd);
    } while (0);
  }
  return 0;
}


x86 assembly (clang, -O0):
<set_dtim>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %edi,-0x8(%rbp)
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1060 <memset@plt>
movl   $0x8,-0x9c(%rbp)
lea    -0xa4(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <memset@plt>
mov    -0x8(%rbp),%edi
lea    -0x94(%rbp),%rsi
call   1070 <nvram_get_ap_dtim@plt>
movl   $0x0,-0xa8(%rbp)
mov    -0xa8(%rbp),%eax
cmp    -0x9c(%rbp),%eax
jge    1284 <set_dtim+0x124>
lea    -0xa4(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0xa8(%rbp),%edx
xor    %ecx,%ecx
call   1030 <construct_vap@plt>
mov    %eax,-0x98(%rbp)
mov    $0xffffffff,%eax
cmp    -0x98(%rbp),%eax
jne    120f <set_dtim+0xaf>
lea    0xe02(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    128b <set_dtim+0x12b>
lea    -0x90(%rbp),%rdi
lea    -0xa4(%rbp),%rdx
mov    -0x94(%rbp),%ecx
lea    0xdf4(%rip),%rsi
call   1080 <sprintf@plt>
lea    0xe01(%rip),%rdi
call   1050 <printf@plt>
lea    -0x90(%rbp),%rdi
call   1050 <printf@plt>
lea    0xdf4(%rip),%rdi
call   1050 <printf@plt>
lea    0xdc2(%rip),%rdi
call   1050 <printf@plt>
lea    -0x90(%rbp),%rdi
call   1040 <system@plt>
jmp    1270 <set_dtim+0x110>
mov    -0xa8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xa8(%rbp)
jmp    11b7 <set_dtim+0x57>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_dtim>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
mov    %edi,%r14d
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)
lea    0x4(%rsp),%rsi
call   1080 <nvram_get_ap_dtim@plt>
xor    %ebp,%ebp
lea    0x8(%rsp),%r12
lea    0x10(%rsp),%rbx
lea    0xe41(%rip),%r13
lea    0xe45(%rip),%r15
nop
mov    %r12,%rdi
mov    %r14d,%esi
mov    %ebp,%edx
xor    %ecx,%ecx
call   1040 <construct_vap@plt>
cmp    $0xffffffff,%eax
je     1240 <set_dtim+0xd0>
mov    0x4(%rsp),%ecx
mov    %rbx,%rdi
lea    0xdfe(%rip),%rsi
mov    %r12,%rdx
call   1090 <sprintf@plt>
mov    %r13,%rdi
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1070 <printf@plt>
mov    %r15,%rdi
call   1070 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1060 <system@plt>
add    $0x1,%ebp
cmp    $0x8,%ebp
jne    11e0 <set_dtim+0x70>
xor    %eax,%eax
jmp    1251 <set_dtim+0xe1>
lea    0xde2(%rip),%rdi
call   1050 <puts@plt>
mov    $0xffffffff,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"ERROR:Construct VAP failure!\0A\00"
@.str.1 = [25 x i8] c"iwpriv %s dtim_period %d\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_dtim(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [128 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [8 x i8]
%9 = alloca i32
store i32 %0, i32* %3
%10 = bitcast [128 x i8]* %4 to i8*
store i32 8, i32* %7
%11 = bitcast [8 x i8]* %8 to i8*
%12 = load i32, i32* %3
%13 = call i32 @nvram_get_ap_dtim(i32 %12, i32* %5)
store i32 0, i32* %9
br label %14
14: ; preds = %41, %1
%15 = load i32, i32* %9
%16 = load i32, i32* %7
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %44
18: ; preds = %14
%19 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%20 = load i32, i32* %3
%21 = load i32, i32* %9
%22 = call i32 @construct_vap(i8* %19, i32 %20, i32 %21, i32 0)
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = icmp eq i32 -1, %23
br i1 %24, label %25, label %27
25: ; preds = %18
%26 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %45
27: ; preds = %18
%28 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%29 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%30 = load i32, i32* %5
%31 = call i32 @sprintf(i8* %28, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %29, i32 %30)
br label %32
32: ; preds = %27
%33 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%34 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%35 = call i32 @printf(i8* %34)
%36 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%37 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%38 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%39 = call i32 @system(i8* %38)
br label %40
40: ; preds = %32
br label %41
41: ; preds = %40
%42 = load i32, i32* %9
%43 = add nsw i32 %42, 1
store i32 %43, i32* %9
br label %14
44: ; preds = %14
store i32 0, i32* %2
br label %45
45: ; preds = %44, %25
%46 = load i32, i32* %2
ret i32 %46
}

LLVM IR (-O2):
@.str.1 = [25 x i8] c"iwpriv %s dtim_period %d\00"
@.str.2 = [11 x i8] c"\1B[1;33;40m\00"
@.str.3 = [5 x i8] c"\1B[0m\00"
@str = [29 x i8] c"ERROR:Construct VAP failure!\00"
define i32 @set_dtim(i32 %0) {
%2 = alloca [128 x i8]
%3 = alloca i32
%4 = alloca i64
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%6 = bitcast i32* %3 to i8*
%7 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%8 = call i32 @nvram_get_ap_dtim(i32 %0, i32* %3)
br label %9
9: ; preds = %1, %15
%10 = phi i32 [ 0, %1 ], [ %23, %15 ]
%11 = call i32 @construct_vap(i8* %7, i32 %0, i32 %10, i32 0)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
br label %25
15: ; preds = %9
%16 = load i32, i32* %3
%17 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %7, i32 %16)
%18 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%19 = call i32 @printf(i8* %5)
%20 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%21 = call i32 @putchar(i32 10)
%22 = call i32 @system(i8* %5)
%23 = add nuw nsw i32 %10, 1
%24 = icmp eq i32 %23, 8
br i1 %24, label %25, label %9
25: ; preds = %15, %13
%26 = phi i32 [ -1, %13 ], [ 0, %15 ]
ret i32 %26
}