#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 sockaddr_in {
  int /*<<< orphan*/ sin_addr;
};
struct ifreq {
  char *ifr_name;
  int /*<<< orphan*/ ifr_addr;
};

/* Variables and functions */
int IFNAMSIZ;
int /*<<< orphan*/ SIOCGIFADDR;
char *inet_ntoa(int /*<<< orphan*/);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, struct ifreq *);
int /*<<< orphan*/ printf(char *);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
int get_wireless_iface_ipaddr(char *ipstr, int sockfd) {
  struct ifreq ifr;
  strncpy(ifr.ifr_name, "wlan0", IFNAMSIZ - 1);
  ioctl(sockfd, SIOCGIFADDR, &ifr);
  strncpy(ipstr, inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr),
          16);
  if (strncmp(ipstr, "0.0.0.0", 16) == 0) {
    printf("The requested interface does not have an IP");
    return -1;
  }
  return 1;
}


x86 assembly (clang, -O0):
<get_wireless_iface_ipaddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x28(%rbp),%rdi
mov    0x2e6e(%rip),%rax
mov    (%rax),%edx
sub    $0x1,%edx
lea    0xe8a(%rip),%rsi
call   1030 <strncpy@plt>
mov    -0x14(%rbp),%edi
mov    0x2e63(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1070 <ioctl@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%edi
call   1050 <inet_ntoa@plt>
mov    -0x30(%rbp),%rdi
mov    %rax,%rsi
mov    $0x10,%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rdi
lea    0xe4a(%rip),%rsi
mov    $0x10,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    11e8 <get_wireless_iface_ipaddr+0x98>
lea    0xe37(%rip),%rdi
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ef <get_wireless_iface_ipaddr+0x9f>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_wireless_iface_ipaddr>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebp
mov    %rdi,%rbx
mov    0x2e76(%rip),%rax
mov    (%rax),%edx
add    $0xffffffff,%edx
lea    0xe92(%rip),%rsi
call   1030 <strncpy@plt>
mov    0x2e6e(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebp,%edi
call   1070 <ioctl@plt>
mov    0x10(%rsp),%edi
call   1050 <inet_ntoa@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
mov    $0x10,%edx
call   1030 <strncpy@plt>
lea    0xe5e(%rip),%rsi
mov    %rbx,%rdi
mov    $0x10,%edx
call   1040 <strncmp@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
jne    11d3 <get_wireless_iface_ipaddr+0x83>
lea    0xe45(%rip),%rdi
call   1060 <printf@plt>
mov    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.ifreq = type { i8*, i32 }
%struct.sockaddr_in = type { i32 }
@.str = [6 x i8] c"wlan0\00"
@IFNAMSIZ = global i32 0
@SIOCGIFADDR = global i32 0
@.str.1 = [8 x i8] c"0.0.0.0\00"
@.str.2 = [44 x i8] c"The requested interface does not have an IP\00"
define i32 @get_wireless_iface_ipaddr(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca %struct.ifreq
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %6, i32 0, i32 0
%8 = load i8*, i8** %7
%9 = load i32, i32* @IFNAMSIZ
%10 = sub nsw i32 %9, 1
%11 = call i32 @strncpy(i8* %8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = load i32, i32* %5
%13 = load i32, i32* @SIOCGIFADDR
%14 = call i32 @ioctl(i32 %12, i32 %13, %struct.ifreq* %6)
%15 = load i8*, i8** %4
%16 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %6, i32 0, i32 1
%17 = bitcast i32* %16 to %struct.sockaddr_in*
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %17, i32 0, i32 0
%19 = load i32, i32* %18
%20 = call i8* @inet_ntoa(i32 %19)
%21 = call i32 @strncpy(i8* %15, i8* %20, i32 16)
%22 = load i8*, i8** %4
%23 = call i64 @strncmp(i8* %22, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 16)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %2
%26 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %28
27: ; preds = %2
store i32 1, i32* %3
br label %28
28: ; preds = %27, %25
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
%struct.ifreq = type { i8*, i32 }
@.str = [6 x i8] c"wlan0\00"
@IFNAMSIZ = global i32 0
@SIOCGIFADDR = global i32 0
@.str.1 = [8 x i8] c"0.0.0.0\00"
@.str.2 = [44 x i8] c"The requested interface does not have an IP\00"
define i32 @get_wireless_iface_ipaddr(i8* %0, i32 %1) {
%3 = alloca %struct.ifreq
%4 = bitcast %struct.ifreq* %3 to i8*
%5 = load i32, i32* @IFNAMSIZ
%6 = add nsw i32 %5, -1
%7 = tail call i32 @strncpy(i8* undef, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = load i32, i32* @SIOCGIFADDR
%9 = call i32 @ioctl(i32 %1, i32 %8, %struct.ifreq* %3)
%10 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i64 0, i32 1
%11 = load i32, i32* %10
%12 = call i8* @inet_ntoa(i32 %11)
%13 = call i32 @strncpy(i8* %0, i8* %12, i32 16)
%14 = call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 16)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
br label %18
18: ; preds = %2, %16
%19 = phi i32 [ -1, %16 ], [ 1, %2 ]
ret i32 %19
}