#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;
scalar_t__ IFNAMSIZ;
int /*<<< orphan*/ SIOCGIFADDR;
int /*<<< orphan*/ SIOCGIFNETMASK;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
char *inet_ntoa(int /*<<< orphan*/);
int ioctl(int, int /*<<< orphan*/, struct ifreq *);
int /*<<< orphan*/ printf(char *, char *, ...);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int strlen(char *);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char *, scalar_t__);
int main(int argc, char **argv) {
  int sock;
  struct ifreq ifr;
  char *interface;
  sock = socket(AF_INET, SOCK_DGRAM, 0);
  if (argc != 2) {
    fprintf(stderr, "usage: %s iface\n", argv[0]);
    return 1;
  } else if (strlen(argv[1]) < 2) {
    fputs("length of the interface must be at least 2 characters.\n", stderr);
    return 2;
  }
  interface = argv[1];
  ifr.ifr_addr.sa_family = AF_INET;
  strncpy(ifr.ifr_name, interface, IFNAMSIZ - 1);
  if (ioctl(sock, SIOCGIFADDR, &ifr) == -1) {
    printf("An Error occured: %s\n", strerror(errno));
    return (3);
  }
  printf("IP address of %s: %s\n", interface,
         inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr));
  if (ioctl(sock, SIOCGIFNETMASK, &ifr) == -1) {
    printf("An Error occured: %s\n", strerror(errno));
    return (3);
  }
  printf("Netmask of %s: %s\n", interface,
         inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr));
  close(sock);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
mov    0x2e0a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1204 <main+0x64>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe0d(%rip),%rsi
call   10a0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    135d <main+0x1bd>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <strlen@plt>
cmp    $0x2,%eax
jge    123b <main+0x9b>
mov    0x2d9f(%rip),%rax
mov    (%rax),%esi
lea    0xde7(%rip),%rdi
call   1070 <fputs@plt>
movl   $0x2,-0x4(%rbp)
jmp    135d <main+0x1bd>
jmp    1240 <main+0xa0>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    0x2d8d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    0x2d52(%rip),%rax
mov    (%rax),%rdx
sub    $0x1,%rdx
call   1030 <strncpy@plt>
mov    -0x14(%rbp),%edi
mov    0x2d6c(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1080 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    12bb <main+0x11b>
mov    0x2d19(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    %rax,%rsi
lea    0xda1(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x3,-0x4(%rbp)
jmp    135d <main+0x1bd>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    -0x30(%rbp),%rsi
mov    %rax,%rdx
lea    0xd86(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
mov    0x2cee(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1080 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    1329 <main+0x189>
mov    0x2cab(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    %rax,%rsi
lea    0xd33(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x3,-0x4(%rbp)
jmp    135d <main+0x1bd>
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    -0x38(%rbp),%rsi
mov    %rax,%rdx
lea    0xd2e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbp
mov    %edi,%ebx
mov    0x2e28(%rip),%r12
mov    (%r12),%edi
mov    0x2e0d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
cmp    $0x2,%ebx
jne    1201 <main+0x61>
mov    %eax,%r15d
mov    0x8(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x1,%eax
jg     1224 <main+0x84>
mov    0x2dd7(%rip),%rax
mov    (%rax),%esi
lea    0xe1f(%rip),%rdi
call   1070 <fputs@plt>
mov    $0x2,%ebp
jmp    12e6 <main+0x146>
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
lea    0xdeb(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1,%ebp
jmp    12e6 <main+0x146>
mov    0x8(%rbp),%r14
mov    (%r12),%eax
mov    %eax,0x8(%rsp)
mov    0x2d81(%rip),%rax
mov    (%rax),%rdx
add    $0xffffffffffffffff,%rdx
mov    %r14,%rsi
call   1030 <strncpy@plt>
mov    0x2d9b(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %r15d,%edi
call   1080 <ioctl@plt>
cmp    $0xffffffff,%eax
je     12c2 <main+0x122>
mov    0x8(%rsp),%edi
call   1040 <inet_ntoa@plt>
lea    0xdee(%rip),%rdi
xor    %ebp,%ebp
mov    %r14,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2d51(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %r15d,%edi
call   1080 <ioctl@plt>
cmp    $0xffffffff,%eax
je     12c2 <main+0x122>
mov    0x8(%rsp),%edi
call   1040 <inet_ntoa@plt>
lea    0xdca(%rip),%rdi
mov    %r14,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r15d,%edi
call   1090 <close@plt>
jmp    12e6 <main+0x146>
mov    0x2ce7(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd72(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x3,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
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 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@stderr = global i32 0
@.str = [17 x i8] c"usage: %s iface\0A\00"
@.str.1 = [56 x i8] c"length of the interface must be at least 2 characters.\0A\00"
@IFNAMSIZ = global i64 0
@SIOCGIFADDR = global i32 0
@.str.2 = [22 x i8] c"An Error occured: %s\0A\00"
@errno = global i32 0
@.str.3 = [22 x i8] c"IP address of %s: %s\0A\00"
@SIOCGIFNETMASK = global i32 0
@.str.4 = [19 x i8] c"Netmask of %s: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.ifreq
%8 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%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* %6
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 2
br i1 %13, label %14, label %20
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %18)
store i32 1, i32* %3
br label %77
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32 @strlen(i8* %23)
%25 = icmp slt i32 %24, 2
br i1 %25, label %26, label %29
26: ; preds = %20
%27 = load i32, i32* @stderr
%28 = call i32 @fputs(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i32 %27)
store i32 2, i32* %3
br label %77
29: ; preds = %20
br label %30
30: ; preds = %29
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
store i8* %33, i8** %8
%34 = load i32, i32* @AF_INET
%35 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %7, i32 0, i32 0
%36 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %35, i32 0, i32 0
store i32 %34, i32* %36
%37 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %7, i32 0, i32 1
%38 = load i32, i32* %37
%39 = load i8*, i8** %8
%40 = load i64, i64* @IFNAMSIZ
%41 = sub nsw i64 %40, 1
%42 = call i32 @strncpy(i32 %38, i8* %39, i64 %41)
%43 = load i32, i32* %6
%44 = load i32, i32* @SIOCGIFADDR
%45 = call i32 @ioctl(i32 %43, i32 %44, %struct.ifreq* %7)
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %51
47: ; preds = %30
%48 = load i32, i32* @errno
%49 = call i8* @strerror(i32 %48)
%50 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %49)
store i32 3, i32* %3
br label %77
51: ; preds = %30
%52 = load i8*, i8** %8
%53 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %7, i32 0, i32 0
%54 = bitcast %struct.TYPE_2__* %53 to %struct.sockaddr_in*
%55 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %54, i32 0, i32 0
%56 = load i32, i32* %55
%57 = call i8* @inet_ntoa(i32 %56)
%58 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %52, i8* %57)
%59 = load i32, i32* %6
%60 = load i32, i32* @SIOCGIFNETMASK
%61 = call i32 @ioctl(i32 %59, i32 %60, %struct.ifreq* %7)
%62 = icmp eq i32 %61, -1
br i1 %62, label %63, label %67
63: ; preds = %51
%64 = load i32, i32* @errno
%65 = call i8* @strerror(i32 %64)
%66 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %65)
store i32 3, i32* %3
br label %77
67: ; preds = %51
%68 = load i8*, i8** %8
%69 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %7, i32 0, i32 0
%70 = bitcast %struct.TYPE_2__* %69 to %struct.sockaddr_in*
%71 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %70, i32 0, i32 0
%72 = load i32, i32* %71
%73 = call i8* @inet_ntoa(i32 %72)
%74 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %68, i8* %73)
%75 = load i32, i32* %6
%76 = call i32 @close(i32 %75)
store i32 0, i32* %3
br label %77
77: ; preds = %67, %63, %47, %26, %14
%78 = load i32, i32* %3
ret i32 %78
}

LLVM IR (-O2):
%struct.ifreq = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@stderr = global i32 0
@.str = [17 x i8] c"usage: %s iface\0A\00"
@.str.1 = [56 x i8] c"length of the interface must be at least 2 characters.\0A\00"
@IFNAMSIZ = global i64 0
@SIOCGIFADDR = global i32 0
@.str.2 = [22 x i8] c"An Error occured: %s\0A\00"
@errno = global i32 0
@.str.3 = [22 x i8] c"IP address of %s: %s\0A\00"
@SIOCGIFNETMASK = global i32 0
@.str.4 = [19 x i8] c"Netmask of %s: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.ifreq
%4 = bitcast %struct.ifreq* %3 to i8*
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_DGRAM
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 0)
%8 = icmp eq i32 %0, 2
br i1 %8, label %13, label %9
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = load i8*, i8** %1
%12 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %11)
br label %51
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call i32 @strlen(i8* %15)
%17 = icmp slt i32 %16, 2
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = load i32, i32* @stderr
%20 = tail call i32 @fputs(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i32 %19)
br label %51
21: ; preds = %13
%22 = load i8*, i8** %14
%23 = load i32, i32* @AF_INET
%24 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i64 0, i32 0, i32 0
store i32 %23, i32* %24
%25 = load i64, i64* @IFNAMSIZ
%26 = add nsw i64 %25, -1
%27 = tail call i32 @strncpy(i32 undef, i8* %22, i64 %26)
%28 = load i32, i32* @SIOCGIFADDR
%29 = call i32 @ioctl(i32 %7, i32 %28, %struct.ifreq* %3)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %35
31: ; preds = %21
%32 = load i32, i32* @errno
%33 = call i8* @strerror(i32 %32)
%34 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %33)
br label %51
35: ; preds = %21
%36 = load i32, i32* %24
%37 = call i8* @inet_ntoa(i32 %36)
%38 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %22, i8* %37)
%39 = load i32, i32* @SIOCGIFNETMASK
%40 = call i32 @ioctl(i32 %7, i32 %39, %struct.ifreq* %3)
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %46
42: ; preds = %35
%43 = load i32, i32* @errno
%44 = call i8* @strerror(i32 %43)
%45 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %44)
br label %51
46: ; preds = %35
%47 = load i32, i32* %24
%48 = call i8* @inet_ntoa(i32 %47)
%49 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %22, i8* %48)
%50 = call i32 @close(i32 %7)
br label %51
51: ; preds = %46, %42, %31, %18, %9
%52 = phi i32 [ 1, %9 ], [ 2, %18 ], [ 3, %31 ], [ 3, %42 ], [ 0, %46 ]
ret i32 %52
}