#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*/ SIOCGIFNETMASK;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
char *getIP(char *);
int /*<<< orphan*/ inet_ntoa(int /*<<< orphan*/);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, struct ifreq *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char *, int);
int /*<<< orphan*/ sscanf(int /*<<< orphan*/, char *, int *, int *, int *,
                          int *);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char *, scalar_t__);
char *getMask(char *dev) {
  struct ifreq ifr;
  int fdSock, i, m1, m2, m3, m4, bits = 0;
  static char output[20];
  fdSock = socket(AF_INET, SOCK_DGRAM, 0);
  ifr.ifr_addr.sa_family = AF_INET;
  strncpy(ifr.ifr_name, dev, IFNAMSIZ - 1);
  ioctl(fdSock, SIOCGIFNETMASK, &ifr);
  close(fdSock);
  sscanf(inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr),
         "%d.%d.%d.%d", &m1, &m2, &m3, &m4);
  for (i = 0; i < 8; i++) {
    if (m1 & 1)
      bits++;
    m1 = m1 >> 1;
    if (m2 & 1)
      bits++;
    m2 = m2 >> 1;
    if (m3 & 1)
      bits++;
    m3 = m3 >> 1;
    if (m4 & 1)
      bits++;
    m4 = m4 >> 1;
  }
  sprintf(output, "%s/%d", getIP(dev), bits);
  return output;
}


x86 assembly (clang, -O0):
<getMask>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
mov    0x2e35(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e32(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    0x2dff(%rip),%rax
mov    (%rax),%rdx
sub    $0x1,%rdx
call   1030 <strncpy@plt>
mov    -0x14(%rbp),%edi
mov    0x2e01(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1050 <ioctl@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    -0x10(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    %eax,%edi
lea    0xdfd(%rip),%rsi
lea    -0x1c(%rbp),%rdx
lea    -0x20(%rbp),%rcx
lea    -0x24(%rbp),%r8
lea    -0x28(%rbp),%r9
call   1070 <sscanf@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x8,-0x18(%rbp)
jge    12bb <getMask+0x13b>
mov    -0x1c(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1241 <getMask+0xc1>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x1c(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1262 <getMask+0xe2>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1283 <getMask+0x103>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x24(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x28(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     12a4 <getMask+0x124>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    121f <getMask+0x9f>
mov    -0x8(%rbp),%rdi
call   1090 <getIP@plt>
mov    %rax,%rdx
mov    -0x2c(%rbp),%ecx
lea    0x2d9f(%rip),%rdi
lea    0xd34(%rip),%rsi
call   1080 <sprintf@plt>
lea    0x2d8c(%rip),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getMask>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%r14
mov    0x2e56(%rip),%rbx
mov    (%rbx),%edi
mov    0x2e3d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,%ebp
mov    (%rbx),%eax
mov    %eax,0x18(%rsp)
mov    0x2e15(%rip),%rax
mov    (%rax),%rdx
add    $0xffffffffffffffff,%rdx
mov    %r14,%rsi
call   1030 <strncpy@plt>
mov    0x2e17(%rip),%rax
mov    (%rax),%esi
lea    0x18(%rsp),%rdx
mov    %ebp,%edi
call   1050 <ioctl@plt>
mov    %ebp,%edi
call   1060 <close@plt>
mov    0x18(%rsp),%edi
call   1040 <inet_ntoa@plt>
lea    0xe12(%rip),%rsi
lea    0x14(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0xc(%rsp),%r8
lea    0x8(%rsp),%r9
mov    %eax,%edi
call   1070 <sscanf@plt>
mov    0x14(%rsp),%ebx
mov    0x10(%rsp),%r8d
mov    0xc(%rsp),%r9d
mov    0x8(%rsp),%r10d
mov    %ebx,%edi
and    $0x1,%edi
mov    %ebx,%eax
shr    %eax
mov    %r8d,%ecx
and    $0x1,%ecx
add    %edi,%ecx
mov    %r8d,%edi
shr    %edi
mov    %r9d,%edx
and    $0x1,%edx
add    %ecx,%edx
mov    %r9d,%ecx
shr    %ecx
mov    %r10d,%esi
and    $0x1,%esi
add    %edx,%esi
mov    %r10d,%edx
shr    %edx
and    $0x1,%eax
add    %esi,%eax
mov    %ebx,%esi
shr    $0x2,%esi
and    $0x1,%edi
add    %eax,%edi
mov    %r8d,%eax
shr    $0x2,%eax
and    $0x1,%ecx
add    %edi,%ecx
mov    %r9d,%edi
shr    $0x2,%edi
and    $0x1,%edx
add    %ecx,%edx
mov    %r10d,%ecx
shr    $0x2,%ecx
and    $0x1,%esi
add    %edx,%esi
mov    %ebx,%edx
shr    $0x3,%edx
and    $0x1,%eax
add    %esi,%eax
mov    %r8d,%esi
shr    $0x3,%esi
and    $0x1,%edi
add    %eax,%edi
mov    %r9d,%eax
shr    $0x3,%eax
and    $0x1,%ecx
add    %edi,%ecx
mov    %r10d,%edi
shr    $0x3,%edi
and    $0x1,%edx
add    %ecx,%edx
mov    %ebx,%ecx
shr    $0x4,%ecx
and    $0x1,%esi
add    %edx,%esi
mov    %r8d,%edx
shr    $0x4,%edx
and    $0x1,%eax
add    %esi,%eax
mov    %r9d,%esi
shr    $0x4,%esi
and    $0x1,%edi
add    %eax,%edi
mov    %r10d,%eax
shr    $0x4,%eax
and    $0x1,%ecx
add    %edi,%ecx
mov    %ebx,%edi
shr    $0x5,%edi
and    $0x1,%edx
add    %ecx,%edx
mov    %r8d,%ecx
shr    $0x5,%ecx
and    $0x1,%esi
add    %edx,%esi
mov    %r9d,%edx
shr    $0x5,%edx
and    $0x1,%eax
add    %esi,%eax
mov    %r10d,%esi
shr    $0x5,%esi
and    $0x1,%edi
add    %eax,%edi
mov    %ebx,%eax
shr    $0x6,%eax
and    $0x1,%ecx
add    %edi,%ecx
mov    %r8d,%edi
shr    $0x6,%edi
and    $0x1,%edx
add    %ecx,%edx
mov    %r9d,%ecx
shr    $0x6,%ecx
and    $0x1,%esi
add    %edx,%esi
mov    %r10d,%edx
shr    $0x6,%edx
and    $0x1,%eax
add    %esi,%eax
mov    %ebx,%esi
shr    $0x7,%esi
and    $0x1,%edi
add    %eax,%edi
mov    %r8d,%eax
shr    $0x7,%eax
and    $0x1,%ecx
add    %edi,%ecx
mov    %r9d,%edi
shr    $0x7,%edi
and    $0x1,%edx
add    %ecx,%edx
mov    %r10d,%ebp
shr    $0x7,%ebp
and    $0x1,%esi
add    %edx,%esi
sar    $0x8,%ebx
and    $0x1,%eax
add    %esi,%eax
sar    $0x8,%r8d
and    $0x1,%edi
add    %eax,%edi
sar    $0x8,%r9d
and    $0x1,%ebp
add    %edi,%ebp
sar    $0x8,%r10d
mov    %ebx,0x14(%rsp)
mov    %r8d,0x10(%rsp)
mov    %r9d,0xc(%rsp)
mov    %r10d,0x8(%rsp)
mov    %r14,%rdi
call   1090 <getIP@plt>
lea    0x2cdd(%rip),%rbx
lea    0xc72(%rip),%rsi
mov    %rbx,%rdi
mov    %rax,%rdx
mov    %ebp,%ecx
call   1080 <sprintf@plt>
mov    %rbx,%rax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.ifreq = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr_in = type { i32 }
@getMask.output = internal global [20 x i8] zeroinitializer
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IFNAMSIZ = global i64 0
@SIOCGIFNETMASK = global i32 0
@.str = [12 x i8] c"%d.%d.%d.%d\00"
@.str.1 = [6 x i8] c"%s/%d\00"
define i8* @getMask(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.ifreq
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %10
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_DGRAM
%13 = call i32 @socket(i32 %11, i32 %12, i32 0)
store i32 %13, i32* %4
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i32 0, i32 0
%16 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %15, i32 0, i32 0
store i32 %14, i32* %16
%17 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i32 0, i32 1
%18 = load i32, i32* %17
%19 = load i8*, i8** %2
%20 = load i64, i64* @IFNAMSIZ
%21 = sub nsw i64 %20, 1
%22 = call i32 @strncpy(i32 %18, i8* %19, i64 %21)
%23 = load i32, i32* %4
%24 = load i32, i32* @SIOCGIFNETMASK
%25 = call i32 @ioctl(i32 %23, i32 %24, %struct.ifreq* %3)
%26 = load i32, i32* %4
%27 = call i32 @close(i32 %26)
%28 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i32 0, i32 0
%29 = bitcast %struct.TYPE_2__* %28 to %struct.sockaddr_in*
%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 @sscanf(i32 %32, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32* %6, i32* %7, i32* %8, i32* %9)
store i32 0, i32* %5
br label %34
34: ; preds = %74, %1
%35 = load i32, i32* %5
%36 = icmp slt i32 %35, 8
br i1 %36, label %37, label %77
37: ; preds = %34
%38 = load i32, i32* %6
%39 = and i32 %38, 1
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %37
%42 = load i32, i32* %10
%43 = add nsw i32 %42, 1
store i32 %43, i32* %10
br label %44
44: ; preds = %41, %37
%45 = load i32, i32* %6
%46 = ashr i32 %45, 1
store i32 %46, i32* %6
%47 = load i32, i32* %7
%48 = and i32 %47, 1
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %53
50: ; preds = %44
%51 = load i32, i32* %10
%52 = add nsw i32 %51, 1
store i32 %52, i32* %10
br label %53
53: ; preds = %50, %44
%54 = load i32, i32* %7
%55 = ashr i32 %54, 1
store i32 %55, i32* %7
%56 = load i32, i32* %8
%57 = and i32 %56, 1
%58 = icmp ne i32 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %53
%60 = load i32, i32* %10
%61 = add nsw i32 %60, 1
store i32 %61, i32* %10
br label %62
62: ; preds = %59, %53
%63 = load i32, i32* %8
%64 = ashr i32 %63, 1
store i32 %64, i32* %8
%65 = load i32, i32* %9
%66 = and i32 %65, 1
%67 = icmp ne i32 %66, 0
br i1 %67, label %68, label %71
68: ; preds = %62
%69 = load i32, i32* %10
%70 = add nsw i32 %69, 1
store i32 %70, i32* %10
br label %71
71: ; preds = %68, %62
%72 = load i32, i32* %9
%73 = ashr i32 %72, 1
store i32 %73, i32* %9
br label %74
74: ; preds = %71
%75 = load i32, i32* %5
%76 = add nsw i32 %75, 1
store i32 %76, i32* %5
br label %34
77: ; preds = %34
%78 = load i8*, i8** %2
%79 = call i8* @getIP(i8* %78)
%80 = load i32, i32* %10
%81 = call i32 @sprintf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @getMask.output, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %79, i32 %80)
ret i8* getelementptr inbounds ([20 x i8], [20 x i8]* @getMask.output, i64 0, i64 0)
}

LLVM IR (-O2):
%struct.ifreq = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
@getMask.output = internal global [20 x i8] zeroinitializer
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IFNAMSIZ = global i64 0
@SIOCGIFNETMASK = global i32 0
@.str = [12 x i8] c"%d.%d.%d.%d\00"
@.str.1 = [6 x i8] c"%s/%d\00"
define i8* @getMask(i8* %0) {
%2 = alloca %struct.ifreq
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = bitcast %struct.ifreq* %2 to i8*
%8 = bitcast i32* %3 to i8*
%9 = bitcast i32* %4 to i8*
%10 = bitcast i32* %5 to i8*
%11 = bitcast i32* %6 to i8*
%12 = load i32, i32* @AF_INET
%13 = load i32, i32* @SOCK_DGRAM
%14 = tail call i32 @socket(i32 %12, i32 %13, i32 0)
%15 = load i32, i32* @AF_INET
%16 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %2, i64 0, i32 0, i32 0
store i32 %15, i32* %16
%17 = load i64, i64* @IFNAMSIZ
%18 = add nsw i64 %17, -1
%19 = tail call i32 @strncpy(i32 undef, i8* %0, i64 %18)
%20 = load i32, i32* @SIOCGIFNETMASK
%21 = call i32 @ioctl(i32 %14, i32 %20, %struct.ifreq* %2)
%22 = call i32 @close(i32 %14)
%23 = load i32, i32* %16
%24 = call i32 @inet_ntoa(i32 %23)
%25 = call i32 @sscanf(i32 %24, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32* %3, i32* %4, i32* %5, i32* %6)
%26 = load i32, i32* %3
%27 = load i32, i32* %4
%28 = load i32, i32* %5
%29 = load i32, i32* %6
%30 = and i32 %26, 1
%31 = lshr i32 %26, 1
%32 = and i32 %27, 1
%33 = add nuw nsw i32 %30, %32
%34 = lshr i32 %27, 1
%35 = and i32 %28, 1
%36 = add nuw nsw i32 %33, %35
%37 = lshr i32 %28, 1
%38 = and i32 %29, 1
%39 = add nuw nsw i32 %36, %38
%40 = lshr i32 %29, 1
%41 = and i32 %31, 1
%42 = add nuw nsw i32 %41, %39
%43 = lshr i32 %26, 2
%44 = and i32 %34, 1
%45 = add nuw nsw i32 %42, %44
%46 = lshr i32 %27, 2
%47 = and i32 %37, 1
%48 = add nuw nsw i32 %45, %47
%49 = lshr i32 %28, 2
%50 = and i32 %40, 1
%51 = add nuw nsw i32 %48, %50
%52 = lshr i32 %29, 2
%53 = and i32 %43, 1
%54 = add nuw nsw i32 %53, %51
%55 = lshr i32 %26, 3
%56 = and i32 %46, 1
%57 = add nuw nsw i32 %54, %56
%58 = lshr i32 %27, 3
%59 = and i32 %49, 1
%60 = add nuw nsw i32 %57, %59
%61 = lshr i32 %28, 3
%62 = and i32 %52, 1
%63 = add nuw nsw i32 %60, %62
%64 = lshr i32 %29, 3
%65 = and i32 %55, 1
%66 = add nuw nsw i32 %65, %63
%67 = lshr i32 %26, 4
%68 = and i32 %58, 1
%69 = add nuw nsw i32 %66, %68
%70 = lshr i32 %27, 4
%71 = and i32 %61, 1
%72 = add nuw nsw i32 %69, %71
%73 = lshr i32 %28, 4
%74 = and i32 %64, 1
%75 = add nuw nsw i32 %72, %74
%76 = lshr i32 %29, 4
%77 = and i32 %67, 1
%78 = add nuw nsw i32 %77, %75
%79 = lshr i32 %26, 5
%80 = and i32 %70, 1
%81 = add nuw nsw i32 %78, %80
%82 = lshr i32 %27, 5
%83 = and i32 %73, 1
%84 = add nuw nsw i32 %81, %83
%85 = lshr i32 %28, 5
%86 = and i32 %76, 1
%87 = add nuw nsw i32 %84, %86
%88 = lshr i32 %29, 5
%89 = and i32 %79, 1
%90 = add nuw nsw i32 %89, %87
%91 = lshr i32 %26, 6
%92 = and i32 %82, 1
%93 = add nuw nsw i32 %90, %92
%94 = lshr i32 %27, 6
%95 = and i32 %85, 1
%96 = add nuw nsw i32 %93, %95
%97 = lshr i32 %28, 6
%98 = and i32 %88, 1
%99 = add nuw nsw i32 %96, %98
%100 = lshr i32 %29, 6
%101 = and i32 %91, 1
%102 = add nuw nsw i32 %101, %99
%103 = lshr i32 %26, 7
%104 = and i32 %94, 1
%105 = add nuw nsw i32 %102, %104
%106 = lshr i32 %27, 7
%107 = and i32 %97, 1
%108 = add nuw nsw i32 %105, %107
%109 = lshr i32 %28, 7
%110 = and i32 %100, 1
%111 = add nuw nsw i32 %108, %110
%112 = lshr i32 %29, 7
%113 = and i32 %103, 1
%114 = add nuw nsw i32 %113, %111
%115 = ashr i32 %26, 8
%116 = and i32 %106, 1
%117 = add nuw nsw i32 %114, %116
%118 = ashr i32 %27, 8
%119 = and i32 %109, 1
%120 = add nuw nsw i32 %117, %119
%121 = ashr i32 %28, 8
%122 = and i32 %112, 1
%123 = add nuw nsw i32 %120, %122
%124 = ashr i32 %29, 8
store i32 %115, i32* %3
store i32 %118, i32* %4
store i32 %121, i32* %5
store i32 %124, i32* %6
%125 = call i8* @getIP(i8* %0)
%126 = call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @getMask.output, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %125, i32 %123)
ret i8* getelementptr inbounds ([20 x i8], [20 x i8]* @getMask.output, i64 0, i64 0)
}