#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 */
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int LOG_CONS;
int LOG_PERROR;
int /*<<< orphan*/ LOG_USER;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ getifaddr(char *, char *, int);
int /*<<< orphan*/ openlog(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, char *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  char addr[16];
  if (argc < 2) {
    fprintf(stderr, "Usage:\t%s interface_name\n", argv[0]);
    return 1;
  }
  openlog("testgetifaddr", LOG_CONS | LOG_PERROR, LOG_USER);
  if (getifaddr(argv[1], addr, sizeof(addr)) < 0) {
    fprintf(stderr, "Cannot get address for interface %s.\n", argv[1]);
    return 1;
  }
  printf("Interface %s has IP address %s.\n", argv[1], addr);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1188 <main+0x48>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe89(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1217 <main+0xd7>
mov    0x2e39(%rip),%rax
mov    (%rax),%esi
mov    0x2e48(%rip),%rax
or     (%rax),%esi
mov    0x2e47(%rip),%rax
mov    (%rax),%edx
lea    0xe70(%rip),%rdi
call   1060 <openlog@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x10,%edx
call   1030 <getifaddr@plt>
cmp    $0x0,%rax
jge    11f8 <main+0xb8>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe41(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1217 <main+0xd7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    -0x20(%rbp),%rdx
lea    0xe43(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
cmp    $0x1,%edi
jg     1162 <main+0x22>
mov    0x2e7c(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xea0(%rip),%rsi
jmp    11ca <main+0x8a>
mov    0x2e5f(%rip),%rax
mov    0x2e70(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e6d(%rip),%rax
mov    (%rax),%edx
lea    0xe96(%rip),%rdi
call   1060 <openlog@plt>
mov    0x8(%rbx),%rdi
mov    %rsp,%rsi
mov    $0x10,%edx
call   1030 <getifaddr@plt>
test   %rax,%rax
js     11b6 <main+0x76>
mov    0x8(%rbx),%rsi
lea    0xea4(%rip),%rdi
mov    %rsp,%rdx
call   1040 <printf@plt>
xor    %eax,%eax
jmp    11d4 <main+0x94>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xe5e(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [26 x i8] c"Usage:\09%s interface_name\0A\00"
@.str.1 = [14 x i8] c"testgetifaddr\00"
@LOG_CONS = global i32 0
@LOG_PERROR = global i32 0
@LOG_USER = global i32 0
@.str.2 = [38 x i8] c"Cannot get address for interface %s.\0A\00"
@.str.3 = [33 x i8] c"Interface %s has IP address %s.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [16 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 2
br i1 %8, label %9, label %15
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %13)
store i32 1, i32* %3
br label %39
15: ; preds = %2
%16 = load i32, i32* @LOG_CONS
%17 = load i32, i32* @LOG_PERROR
%18 = or i32 %16, %17
%19 = load i32, i32* @LOG_USER
%20 = call i32 @openlog(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %18, i32 %19)
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%25 = call i64 @getifaddr(i8* %23, i8* %24, i32 16)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %33
27: ; preds = %15
%28 = load i32, i32* @stderr
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i8* %31)
store i32 1, i32* %3
br label %39
33: ; preds = %15
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%38 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %36, i8* %37)
store i32 0, i32* %3
br label %39
39: ; preds = %33, %27, %9
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [26 x i8] c"Usage:\09%s interface_name\0A\00"
@.str.1 = [14 x i8] c"testgetifaddr\00"
@LOG_CONS = global i32 0
@LOG_PERROR = global i32 0
@LOG_USER = global i32 0
@.str.2 = [38 x i8] c"Cannot get address for interface %s.\0A\00"
@.str.3 = [33 x i8] c"Interface %s has IP address %s.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [16 x i8]
%4 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %27
10: ; preds = %2
%11 = load i32, i32* @LOG_CONS
%12 = load i32, i32* @LOG_PERROR
%13 = or i32 %12, %11
%14 = load i32, i32* @LOG_USER
%15 = tail call i32 @openlog(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %13, i32 %14)
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = call i64 @getifaddr(i8* %17, i8* %4, i32 16)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %10
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %16
%23 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i8* %22)
br label %27
24: ; preds = %10
%25 = load i8*, i8** %16
%26 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %25, i8* %4)
br label %27
27: ; preds = %24, %20, %6
%28 = phi i32 [ 1, %6 ], [ 1, %20 ], [ 0, %24 ]
ret i32 %28
}