#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_2__ TYPE_1__;

/* Type definitions */
typedef scalar_t__ u_int32_t;
struct in_addr {
  scalar_t__ s_addr;
};
struct TYPE_2__ {
  int /*<<< orphan*/ sa_data;
};
struct ifreq {
  char *ifr_name;
  TYPE_1__ ifr_addr;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ SIOCGIFADDR;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ _debug(char *, int, int /*<<< orphan*/, char *,
                          int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ free(char *);
scalar_t__ inet_ntop(int /*<<< orphan*/, struct in_addr *, char *, int);
scalar_t__ ioctl(int, int /*<<< orphan*/, struct ifreq *);
char *malloc(int);
int /*<<< orphan*/ memcpy(void *, void *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(char *, char const *, int);
char *strrchr(char *, char);
char *get_iface_ip(const char *ifname) {
  struct ifreq if_data;
  struct in_addr in;
  char *ip_str;
  int sockd;
  u_int32_t ip;
  if ((sockd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
    _debug((strrchr("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                    "outputs/2022-01-22/02-19-57/repos/liudf0716/xkcptun/refs/"
                    "heads/master/xkcp_util.c",
                    '/')
                ? strrchr("/scratch/repos/new/home/jordi_armengol_estape/"
                          "c-scraper/outputs/2022-01-22/02-19-57/repos/"
                          "liudf0716/xkcptun/refs/heads/master/xkcp_util.c",
                          '/') +
                      1
                : "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                  "outputs/2022-01-22/02-19-57/repos/liudf0716/xkcptun/refs/"
                  "heads/master/xkcp_util.c"),
           92, LOG_ERR, "socket(): %s", strerror(errno));
    return NULL;
  }
  strncpy(if_data.ifr_name, ifname, 15);
  if_data.ifr_name[15] = '\0';
  if (ioctl(sockd, SIOCGIFADDR, &if_data) < 0) {
    _debug((strrchr("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                    "outputs/2022-01-22/02-19-57/repos/liudf0716/xkcptun/refs/"
                    "heads/master/xkcp_util.c",
                    '/')
                ? strrchr("/scratch/repos/new/home/jordi_armengol_estape/"
                          "c-scraper/outputs/2022-01-22/02-19-57/repos/"
                          "liudf0716/xkcptun/refs/heads/master/xkcp_util.c",
                          '/') +
                      1
                : "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                  "outputs/2022-01-22/02-19-57/repos/liudf0716/xkcptun/refs/"
                  "heads/master/xkcp_util.c"),
           102, LOG_ERR, "ioctl(): SIOCGIFADDR %s", strerror(errno));
    close(sockd);
    return NULL;
  }
  memcpy((void *)&ip, (void *)&if_data.ifr_addr.sa_data + 2, 4);
  in.s_addr = ip;
  close(sockd);
  ip_str = malloc(16);
  memset(ip_str, 0, 16);
  if (ip_str && inet_ntop(AF_INET, &in, ip_str, 16))
    return ip_str;
  if (ip_str)
    free(ip_str);
  return NULL;
}


x86 assembly (clang, -O0):
<get_iface_ip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
mov    0x2dfc(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jge    1284 <get_iface_ip+0xc4>
lea    0xe08(%rip),%rdi
mov    $0x2f,%esi
call   1060 <strrchr@plt>
cmp    $0x0,%rax
je     122a <get_iface_ip+0x6a>
lea    0xded(%rip),%rdi
mov    $0x2f,%esi
call   1060 <strrchr@plt>
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
jmp    123a <get_iface_ip+0x7a>
lea    0xdcf(%rip),%rax
mov    %rax,-0x48(%rbp)
jmp    123a <get_iface_ip+0x7a>
mov    -0x48(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    0x2d6f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    0x2d73(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x58(%rbp),%rdi
mov    -0x4c(%rbp),%edx
mov    %eax,%r8d
mov    $0x5c,%esi
lea    0xe18(%rip),%rcx
call   10b0 <_debug@plt>
movq   $0x0,-0x8(%rbp)
jmp    13f9 <get_iface_ip+0x239>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0xf,%edx
call   1050 <strncpy@plt>
mov    -0x20(%rbp),%rax
movb   $0x0,0xf(%rax)
mov    -0x34(%rbp),%edi
mov    0x2d40(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1080 <ioctl@plt>
cmp    $0x0,%rax
jge    1358 <get_iface_ip+0x198>
lea    0xd3c(%rip),%rdi
mov    $0x2f,%esi
call   1060 <strrchr@plt>
cmp    $0x0,%rax
je     12f6 <get_iface_ip+0x136>
lea    0xd21(%rip),%rdi
mov    $0x2f,%esi
call   1060 <strrchr@plt>
add    $0x1,%rax
mov    %rax,-0x60(%rbp)
jmp    1306 <get_iface_ip+0x146>
lea    0xd03(%rip),%rax
mov    %rax,-0x60(%rbp)
jmp    1306 <get_iface_ip+0x146>
mov    -0x60(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    0x2ca3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    0x2ca7(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x70(%rbp),%rdi
mov    -0x64(%rbp),%edx
mov    %eax,%r8d
mov    $0x66,%esi
lea    0xd59(%rip),%rcx
call   10b0 <_debug@plt>
mov    -0x34(%rbp),%edi
call   1090 <close@plt>
movq   $0x0,-0x8(%rbp)
jmp    13f9 <get_iface_ip+0x239>
lea    -0x40(%rbp),%rdi
lea    -0x20(%rbp),%rsi
add    $0x8,%rsi
add    $0x2,%rsi
mov    $0x4,%edx
call   10a0 <memcpy@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x34(%rbp),%edi
call   1090 <close@plt>
mov    $0x10,%edi
call   10c0 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1070 <memset@plt>
cmpq   $0x0,-0x30(%rbp)
je     13dd <get_iface_ip+0x21d>
mov    0x2c2e(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rdx
lea    -0x28(%rbp),%rsi
mov    $0x10,%ecx
call   1030 <inet_ntop@plt>
cmp    $0x0,%rax
je     13dd <get_iface_ip+0x21d>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    13f9 <get_iface_ip+0x239>
cmpq   $0x0,-0x30(%rbp)
je     13f1 <get_iface_ip+0x231>
mov    -0x30(%rbp),%rdi
call   1040 <free@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_iface_ip>:
push   %rbx
mov    %rdi,%rbx
mov    0x2e9d(%rip),%rax
mov    (%rax),%edi
mov    0x2e8c(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
test   %eax,%eax
jns    1199 <get_iface_ip+0x59>
mov    0x2e58(%rip),%rax
mov    (%rax),%ebx
mov    0x2e5f(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xeff(%rip),%rdi
lea    0xf04(%rip),%rcx
mov    $0x5c,%esi
mov    %ebx,%edx
mov    %eax,%r8d
call   1040 <_debug@plt>
xor    %eax,%eax
pop    %rbx
ret
mov    %rbx,%rsi
mov    $0xf,%edx
call   1030 <strncpy@plt>

LLVM IR (-O0):
%struct.ifreq = type { i8*, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.in_addr = type { i64 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [138 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/liudf0716/xkcptun/refs/heads/master/xkcp_util.c\00"
@LOG_ERR = global i32 0
@.str.1 = [13 x i8] c"socket(): %s\00"
@errno = global i32 0
@SIOCGIFADDR = global i32 0
@.str.2 = [24 x i8] c"ioctl(): SIOCGIFADDR %s\00"
define i8* @get_iface_ip(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca %struct.ifreq
%5 = alloca %struct.in_addr
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i64
store i8* %0, i8** %3
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_DGRAM
%11 = call i32 @socket(i32 %9, i32 %10, i32 0)
store i32 %11, i32* %7
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %26
13: ; preds = %1
%14 = call i8* @strrchr(i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str, i64 0, i64 0), i8 signext 47)
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = call i8* @strrchr(i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str, i64 0, i64 0), i8 signext 47)
%18 = getelementptr inbounds i8, i8* %17, i64 1
br label %20
19: ; preds = %13
br label %20
20: ; preds = %19, %16
%21 = phi i8* [ %18, %16 ], [ getelementptr inbounds ([138 x i8], [138 x i8]* @.str, i64 0, i64 0), %19 ]
%22 = load i32, i32* @LOG_ERR
%23 = load i32, i32* @errno
%24 = call i32 @strerror(i32 %23)
%25 = call i32 @_debug(i8* %21, i32 92, i32 %22, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %24)
store i8* null, i8** %2
br label %83
26: ; preds = %1
%27 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %4, i32 0, i32 0
%28 = load i8*, i8** %27
%29 = load i8*, i8** %3
%30 = call i32 @strncpy(i8* %28, i8* %29, i32 15)
%31 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %4, i32 0, i32 0
%32 = load i8*, i8** %31
%33 = getelementptr inbounds i8, i8* %32, i64 15
store i8 0, i8* %33
%34 = load i32, i32* %7
%35 = load i32, i32* @SIOCGIFADDR
%36 = call i64 @ioctl(i32 %34, i32 %35, %struct.ifreq* %4)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %53
38: ; preds = %26
%39 = call i8* @strrchr(i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str, i64 0, i64 0), i8 signext 47)
%40 = icmp ne i8* %39, null
br i1 %40, label %41, label %44
41: ; preds = %38
%42 = call i8* @strrchr(i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str, i64 0, i64 0), i8 signext 47)
%43 = getelementptr inbounds i8, i8* %42, i64 1
br label %45
44: ; preds = %38
br label %45
45: ; preds = %44, %41
%46 = phi i8* [ %43, %41 ], [ getelementptr inbounds ([138 x i8], [138 x i8]* @.str, i64 0, i64 0), %44 ]
%47 = load i32, i32* @LOG_ERR
%48 = load i32, i32* @errno
%49 = call i32 @strerror(i32 %48)
%50 = call i32 @_debug(i8* %46, i32 102, i32 %47, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %49)
%51 = load i32, i32* %7
%52 = call i32 @close(i32 %51)
store i8* null, i8** %2
br label %83
53: ; preds = %26
%54 = bitcast i64* %8 to i8*
%55 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %4, i32 0, i32 1
%56 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %55, i32 0, i32 0
%57 = bitcast i32* %56 to i8*
%58 = getelementptr i8, i8* %57, i64 2
%59 = call i32 @memcpy(i8* %54, i8* %58, i32 4)
%60 = load i64, i64* %8
%61 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %5, i32 0, i32 0
store i64 %60, i64* %61
%62 = load i32, i32* %7
%63 = call i32 @close(i32 %62)
%64 = call i8* @malloc(i32 16)
store i8* %64, i8** %6
%65 = load i8*, i8** %6
%66 = call i32 @memset(i8* %65, i32 0, i32 16)
%67 = load i8*, i8** %6
%68 = icmp ne i8* %67, null
br i1 %68, label %69, label %76
69: ; preds = %53
%70 = load i32, i32* @AF_INET
%71 = load i8*, i8** %6
%72 = call i64 @inet_ntop(i32 %70, %struct.in_addr* %5, i8* %71, i32 16)
%73 = icmp ne i64 %72, 0
br i1 %73, label %74, label %76
74: ; preds = %69
%75 = load i8*, i8** %6
store i8* %75, i8** %2
br label %83
76: ; preds = %69, %53
%77 = load i8*, i8** %6
%78 = icmp ne i8* %77, null
br i1 %78, label %79, label %82
79: ; preds = %76
%80 = load i8*, i8** %6
%81 = call i32 @free(i8* %80)
br label %82
82: ; preds = %79, %76
store i8* null, i8** %2
br label %83
83: ; preds = %82, %74, %45, %20
%84 = load i8*, i8** %2
ret i8* %84
}

LLVM IR (-O2):
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [138 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/liudf0716/xkcptun/refs/heads/master/xkcp_util.c\00"
@LOG_ERR = global i32 0
@.str.1 = [13 x i8] c"socket(): %s\00"
@errno = global i32 0
@SIOCGIFADDR = global i32 0
define i8* @get_iface_ip(i8* %0) {
%2 = load i32, i32* @AF_INET
%3 = load i32, i32* @SOCK_DGRAM
%4 = tail call i32 @socket(i32 %2, i32 %3, i32 0)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %11
6: ; preds = %1
%7 = load i32, i32* @LOG_ERR
%8 = load i32, i32* @errno
%9 = tail call i32 @strerror(i32 %8)
%10 = tail call i32 @_debug(i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str, i64 0, i64 126), i32 92, i32 %7, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %9)
ret i8* null
11: ; preds = %1
%12 = tail call i32 @strncpy(i8* undef, i8* %0, i32 15)
unreachable
}