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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ IFNAMSIZ;
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ SIOCGIFADDR;
int get_sockfd();
int /*<<< orphan*/ inet_ntoa(int /*<<< orphan*/);
scalar_t__ ioctl(int, int /*<<< orphan*/, struct ifreq *);
int /*<<< orphan*/ strcpy(char *, int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char *, int /*<<< orphan*/);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, char *);
int GetIpAddressStr(char *address, char *ifname) {
  struct ifreq ifr;
  struct sockaddr_in *saddr;
  int fd;
  int succeeded = 0;
  fd = get_sockfd();
  if (fd >= 0) {
    strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
    ifr.ifr_addr.sa_family = AF_INET;
    if (ioctl(fd, SIOCGIFADDR, &ifr) == 0) {
      saddr = (struct sockaddr_in *)&ifr.ifr_addr;
      strcpy(address, inet_ntoa(saddr->sin_addr));
      succeeded = 1;
    } else {
      syslog(LOG_ERR, "Failure obtaining ip address of interface %s", ifname);
      succeeded = 0;
    }
  }
  return succeeded;
}


x86 assembly (clang, -O0):
<GetIpAddressStr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x28(%rbp)
mov    $0x0,%al
call   1060 <get_sockfd@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jl     1222 <GetIpAddressStr+0xc2>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    0x2e37(%rip),%rax
mov    (%rax),%edx
call   1030 <strncpy@plt>
mov    0x2e39(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x24(%rbp),%edi
mov    0x2e32(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1070 <ioctl@plt>
cmp    $0x0,%rax
jne    11fd <GetIpAddressStr+0x9d>
lea    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
call   1050 <inet_ntoa@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
call   1040 <strcpy@plt>
movl   $0x1,-0x28(%rbp)
jmp    121d <GetIpAddressStr+0xbd>
mov    0x2dbc(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xdef(%rip),%rsi
call   1080 <syslog@plt>
movl   $0x0,-0x28(%rbp)
jmp    1222 <GetIpAddressStr+0xc2>
mov    -0x28(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetIpAddressStr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
xor    %r15d,%r15d
xor    %eax,%eax
call   1060 <get_sockfd@plt>
test   %eax,%eax
js     11e4 <GetIpAddressStr+0x84>
mov    %eax,%ebp
mov    0x2e4c(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rsi
call   1030 <strncpy@plt>
mov    0x2e4b(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rsp)
mov    0x2e47(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %ebp,%edi
call   1070 <ioctl@plt>
test   %rax,%rax
je     11cc <GetIpAddressStr+0x6c>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
lea    0xe3e(%rip),%rsi
mov    %rbx,%rdx
call   1080 <syslog@plt>
jmp    11e4 <GetIpAddressStr+0x84>
mov    (%rsp),%edi
call   1050 <inet_ntoa@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1040 <strcpy@plt>
mov    $0x1,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ifreq = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr_in = type { i32 }
@IFNAMSIZ = global i32 0
@AF_INET = global i32 0
@SIOCGIFADDR = global i32 0
@LOG_ERR = global i32 0
@.str = [45 x i8] c"Failure obtaining ip address of interface %s\00"
define i32 @GetIpAddressStr(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.ifreq
%6 = alloca %struct.sockaddr_in*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %8
%9 = call i32 (...) @get_sockfd()
store i32 %9, i32* %7
%10 = load i32, i32* %7
%11 = icmp sge i32 %10, 0
br i1 %11, label %12, label %39
12: ; preds = %2
%13 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %5, i32 0, i32 1
%14 = load i32, i32* %13
%15 = load i8*, i8** %4
%16 = load i32, i32* @IFNAMSIZ
%17 = call i32 @strncpy(i32 %14, i8* %15, i32 %16)
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %5, i32 0, i32 0
%20 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %19, i32 0, i32 0
store i32 %18, i32* %20
%21 = load i32, i32* %7
%22 = load i32, i32* @SIOCGIFADDR
%23 = call i64 @ioctl(i32 %21, i32 %22, %struct.ifreq* %5)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %34
25: ; preds = %12
%26 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %5, i32 0, i32 0
%27 = bitcast %struct.TYPE_2__* %26 to %struct.sockaddr_in*
store %struct.sockaddr_in* %27, %struct.sockaddr_in** %6
%28 = load i8*, i8** %3
%29 = load %struct.sockaddr_in*, %struct.sockaddr_in** %6
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %29, i32 0, i32 0
%31 = load i32, i32* %30
%32 = call i32 @inet_ntoa(i32 %31)
%33 = call i32 @strcpy(i8* %28, i32 %32)
store i32 1, i32* %8
br label %38
34: ; preds = %12
%35 = load i32, i32* @LOG_ERR
%36 = load i8*, i8** %4
%37 = call i32 @syslog(i32 %35, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %36)
store i32 0, i32* %8
br label %38
38: ; preds = %34, %25
br label %39
39: ; preds = %38, %2
%40 = load i32, i32* %8
ret i32 %40
}

LLVM IR (-O2):
%struct.ifreq = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
@IFNAMSIZ = global i32 0
@AF_INET = global i32 0
@SIOCGIFADDR = global i32 0
@LOG_ERR = global i32 0
@.str = [45 x i8] c"Failure obtaining ip address of interface %s\00"
define i32 @GetIpAddressStr(i8* %0, i8* %1) {
%3 = alloca %struct.ifreq
%4 = bitcast %struct.ifreq* %3 to i8*
%5 = tail call i32 (...) @get_sockfd()
%6 = icmp sgt i32 %5, -1
br i1 %6, label %7, label %22
7: ; preds = %2
%8 = load i32, i32* @IFNAMSIZ
%9 = tail call i32 @strncpy(i32 undef, i8* %1, i32 %8)
%10 = load i32, i32* @AF_INET
%11 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i64 0, i32 0, i32 0
store i32 %10, i32* %11
%12 = load i32, i32* @SIOCGIFADDR
%13 = call i64 @ioctl(i32 %5, i32 %12, %struct.ifreq* %3)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %7
%16 = load i32, i32* %11
%17 = call i32 @inet_ntoa(i32 %16)
%18 = call i32 @strcpy(i8* %0, i32 %17)
br label %22
19: ; preds = %7
%20 = load i32, i32* @LOG_ERR
%21 = call i32 @syslog(i32 %20, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %22
22: ; preds = %15, %19, %2
%23 = phi i32 [ 1, %15 ], [ 0, %19 ], [ 0, %2 ]
ret i32 %23
}