#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 */
typedef struct TYPE_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  int /*<<< orphan*/ length;
  scalar_t__ pointer;
};
struct TYPE_4__ {
  TYPE_1__ data;
};
struct iwreq {
  TYPE_2__ u;
};
typedef scalar_t__ caddr_t;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
scalar_t__ iw_get_ext(int, char *, unsigned int, struct iwreq *);
int /*<<< orphan*/ printf(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int MP_get_ext(char *ifname, char *buf, unsigned int ext_num) {
  int skfd;
  struct iwreq wrq;
  skfd = socket(AF_INET, SOCK_DGRAM, 0);
  wrq.u.data.pointer = (caddr_t)buf;
  wrq.u.data.length = strlen(buf);
  if (iw_get_ext(skfd, ifname, ext_num, &wrq) < 0) {
    printf("MP_get_ext failed\n");
    return -1;
  }
  close(skfd);
  return 0;
}


x86 assembly (clang, -O0):
<MP_get_ext>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    0x2e7e(%rip),%rax
mov    (%rax),%edi
mov    0x2e6d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x30(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    -0x30(%rbp),%rcx
call   1030 <iw_get_ext@plt>
cmp    $0x0,%rax
jge    11c8 <MP_get_ext+0x78>
lea    0xe49(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d7 <MP_get_ext+0x87>
mov    -0x20(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MP_get_ext>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r15d
mov    %rsi,%rbx
mov    %rdi,%r12
mov    0x2e7c(%rip),%rax
mov    (%rax),%edi
mov    0x2e6b(%rip),%rax
mov    (%rax),%esi
xor    %r14d,%r14d
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,%ebp
mov    %rbx,0x8(%rsp)
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,(%rsp)
mov    %rsp,%rcx
mov    %ebp,%edi
mov    %r12,%rsi
mov    %r15d,%edx
call   1040 <iw_get_ext@plt>
test   %rax,%rax
js     11b1 <MP_get_ext+0x61>
mov    %ebp,%edi
call   1060 <close@plt>
jmp    11c3 <MP_get_ext+0x73>
lea    0xe48(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.iwreq = type { %struct.TYPE_4__ }
%struct.TYPE_4__ = type { %struct.TYPE_3__ }
%struct.TYPE_3__ = type { i32, i64 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [19 x i8] c"MP_get_ext failed\0A\00"
define i32 @MP_get_ext(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.iwreq
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%10 = load i32, i32* @AF_INET
%11 = load i32, i32* @SOCK_DGRAM
%12 = call i32 @socket(i32 %10, i32 %11, i32 0)
store i32 %12, i32* %8
%13 = load i8*, i8** %6
%14 = ptrtoint i8* %13 to i64
%15 = getelementptr inbounds %struct.iwreq, %struct.iwreq* %9, i32 0, i32 0
%16 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %15, i32 0, i32 0
%17 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %16, i32 0, i32 1
store i64 %14, i64* %17
%18 = load i8*, i8** %6
%19 = call i32 @strlen(i8* %18)
%20 = getelementptr inbounds %struct.iwreq, %struct.iwreq* %9, i32 0, i32 0
%21 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %20, i32 0, i32 0
%22 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %21, i32 0, i32 0
store i32 %19, i32* %22
%23 = load i32, i32* %8
%24 = load i8*, i8** %5
%25 = load i32, i32* %7
%26 = call i64 @iw_get_ext(i32 %23, i8* %24, i32 %25, %struct.iwreq* %9)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %3
%29 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %33
30: ; preds = %3
%31 = load i32, i32* %8
%32 = call i32 @close(i32 %31)
store i32 0, i32* %4
br label %33
33: ; preds = %30, %28
%34 = load i32, i32* %4
ret i32 %34
}

LLVM IR (-O2):
%struct.iwreq = type { %struct.TYPE_4__ }
%struct.TYPE_4__ = type { %struct.TYPE_3__ }
%struct.TYPE_3__ = type { i32, i64 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@str = [18 x i8] c"MP_get_ext failed\00"
define i32 @MP_get_ext(i8* %0, i8* %1, i32 %2) {
%4 = alloca %struct.iwreq
%5 = bitcast %struct.iwreq* %4 to i8*
%6 = load i32, i32* @AF_INET
%7 = load i32, i32* @SOCK_DGRAM
%8 = tail call i32 @socket(i32 %6, i32 %7, i32 0)
%9 = ptrtoint i8* %1 to i64
%10 = getelementptr inbounds %struct.iwreq, %struct.iwreq* %4, i64 0, i32 0, i32 0, i32 1
store i64 %9, i64* %10
%11 = tail call i32 @strlen(i8* %1)
%12 = getelementptr inbounds %struct.iwreq, %struct.iwreq* %4, i64 0, i32 0, i32 0, i32 0
store i32 %11, i32* %12
%13 = call i64 @iw_get_ext(i32 %8, i8* %0, i32 %2, %struct.iwreq* %4)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %3
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
br label %19
17: ; preds = %3
%18 = call i32 @close(i32 %8)
br label %19
19: ; preds = %17, %15
%20 = phi i32 [ -1, %15 ], [ 0, %17 ]
ret i32 %20
}