#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;
};

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ wpa_ctrl_close(struct wpa_ctrl *);
struct wpa_ctrl *wpa_ctrl_open(char *);
scalar_t__ wpa_ctrl_request(struct wpa_ctrl *, char *, int /*<<< orphan*/,
                            char *, size_t *, int /*<<< orphan*/ *);
int main(int args, char **argv) {
  struct wpa_ctrl *_ctrl;
  char reply[1024] = {0};
  size_t reply_len = 1024;
  _ctrl = wpa_ctrl_open("/var/run/wpa_supplicant/wlan0");
  if (_ctrl == NULL) {
    printf("open wpa_ctrl error\n");
    return 1;
  }
  if (wpa_ctrl_request(_ctrl, "LIST_NETWORKS", strlen("LIST_NETWORKS"), reply,
                       &reply_len, NULL)) {
    wpa_ctrl_close(_ctrl);
    return 1;
  }
  printf("%s\n", reply);
  wpa_ctrl_close(_ctrl);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
movq   $0x400,-0x428(%rbp)
lea    0xe62(%rip),%rdi
call   1080 <wpa_ctrl_open@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11cc <main+0x6c>
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    124f <main+0xef>
mov    -0x18(%rbp),%rax
mov    %rax,-0x430(%rbp)
lea    0xe55(%rip),%rdi
call   1030 <strlen@plt>
mov    -0x430(%rbp),%rdi
mov    %eax,%edx
lea    -0x420(%rbp),%rcx
lea    0xe39(%rip),%rsi
lea    -0x428(%rbp),%r8
xor    %eax,%eax
mov    %eax,%r9d
call   1070 <wpa_ctrl_request@plt>
cmp    $0x0,%rax
je     122a <main+0xca>
mov    -0x18(%rbp),%rdi
call   1040 <wpa_ctrl_close@plt>
movl   $0x1,-0x4(%rbp)
jmp    124f <main+0xef>
lea    -0x420(%rbp),%rsi
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <wpa_ctrl_close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x410,%rsp
lea    0x10(%rsp),%rdi
mov    $0x400,%edx
xor    %esi,%esi
call   1060 <memset@plt>
movq   $0x400,0x8(%rsp)
lea    0xe73(%rip),%rdi
call   1080 <wpa_ctrl_open@plt>
test   %rax,%rax
je     11db <main+0x7b>
mov    %rax,%rbx
lea    0xe7d(%rip),%r15
mov    %r15,%rdi
call   1040 <strlen@plt>
xor    %r14d,%r14d
lea    0x10(%rsp),%rcx
lea    0x8(%rsp),%r8
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %eax,%edx
xor    %r9d,%r9d
call   1070 <wpa_ctrl_request@plt>
test   %rax,%rax
je     11ef <main+0x8f>
mov    %rbx,%rdi
call   1050 <wpa_ctrl_close@plt>
mov    $0x1,%r14d
jmp    1201 <main+0xa1>
lea    0xe4a(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%r14d
jmp    1201 <main+0xa1>
lea    0x10(%rsp),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1050 <wpa_ctrl_close@plt>
mov    %r14d,%eax
add    $0x410,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.wpa_ctrl = type { i32 }
@.str = [30 x i8] c"/var/run/wpa_supplicant/wlan0\00"
@.str.1 = [21 x i8] c"open wpa_ctrl error\0A\00"
@.str.2 = [14 x i8] c"LIST_NETWORKS\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.wpa_ctrl*
%7 = alloca [1024 x i8]
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = bitcast [1024 x i8]* %7 to i8*
store i64 1024, i64* %8
%10 = call %struct.wpa_ctrl* @wpa_ctrl_open(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
store %struct.wpa_ctrl* %10, %struct.wpa_ctrl** %6
%11 = load %struct.wpa_ctrl*, %struct.wpa_ctrl** %6
%12 = icmp eq %struct.wpa_ctrl* %11, null
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %29
15: ; preds = %2
%16 = load %struct.wpa_ctrl*, %struct.wpa_ctrl** %6
%17 = call i32 @strlen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%19 = call i64 @wpa_ctrl_request(%struct.wpa_ctrl* %16, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %17, i8* %18, i64* %8, i32* null)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %15
%22 = load %struct.wpa_ctrl*, %struct.wpa_ctrl** %6
%23 = call i32 @wpa_ctrl_close(%struct.wpa_ctrl* %22)
store i32 1, i32* %3
br label %29
24: ; preds = %15
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %25)
%27 = load %struct.wpa_ctrl*, %struct.wpa_ctrl** %6
%28 = call i32 @wpa_ctrl_close(%struct.wpa_ctrl* %27)
store i32 0, i32* %3
br label %29
29: ; preds = %24, %21, %13
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
%struct.wpa_ctrl = type { i32 }
@.str = [30 x i8] c"/var/run/wpa_supplicant/wlan0\00"
@.str.2 = [14 x i8] c"LIST_NETWORKS\00"
@str = [20 x i8] c"open wpa_ctrl error\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1024 x i8]
%4 = alloca i64
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = bitcast i64* %4 to i8*
store i64 1024, i64* %4
%7 = tail call %struct.wpa_ctrl* @wpa_ctrl_open(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq %struct.wpa_ctrl* %7, null
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %20
11: ; preds = %2
%12 = tail call i32 @strlen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%13 = call i64 @wpa_ctrl_request(%struct.wpa_ctrl* %7, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %12, i8* %5, i64* %4, i32* null)
%14 = icmp eq i64 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %11
%16 = call i32 @wpa_ctrl_close(%struct.wpa_ctrl* %7)
br label %20
17: ; preds = %11
%18 = call i32 @puts(i8* %5)
%19 = call i32 @wpa_ctrl_close(%struct.wpa_ctrl* %7)
br label %20
20: ; preds = %17, %15, %9
%21 = phi i32 [ 1, %9 ], [ 1, %15 ], [ 0, %17 ]
ret i32 %21
}