#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 */
struct in_addr {
  int s_addr;
};

/* Variables and functions */
int inet_addr(char const *);
int /*<<< orphan*/ inet_ntoa(struct in_addr);
int /*<<< orphan*/ ssystem(char *, char const *, ...);
scalar_t__ strcmp(char const *, char *);
void ifconf(const char *tundev, const char *ipaddr, const char *netmask) {
  struct in_addr netname;
  netname.s_addr = inet_addr(ipaddr) & inet_addr(netmask);
  ssystem("ifconfig %s inet `hostname` up", tundev);
  if (strcmp(ipaddr, "0.0.0.0") != 0) {
    ssystem("route add -net %s netmask %s dev %s", inet_ntoa(netname), netmask,
            tundev);
  }
  ssystem("ifconfig %s\n", tundev);
}


x86 assembly (clang, -O0):
<ifconf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <inet_addr@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <inet_addr@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
and    %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1040 <ssystem@plt>
mov    -0x10(%rbp),%rdi
lea    0xe8f(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     11c0 <ifconf+0x80>
mov    -0x20(%rbp),%edi
call   1030 <inet_ntoa@plt>
movslq %eax,%rsi
mov    -0x18(%rbp),%rdx
mov    -0x8(%rbp),%rcx
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1040 <ssystem@plt>
mov    -0x8(%rbp),%rsi
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1040 <ssystem@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ifconf>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r12
mov    %rsi,%rdi
call   1050 <inet_addr@plt>
mov    %eax,%r15d
mov    %r14,%rdi
call   1050 <inet_addr@plt>
mov    %eax,%ebp
lea    0xe93(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <ssystem@plt>
lea    0xea1(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11ac <ifconf+0x6c>
and    %r15d,%ebp
mov    %ebp,%edi
call   1030 <inet_ntoa@plt>
movslq %eax,%rsi
lea    0xe88(%rip),%rdi
mov    %r14,%rdx
mov    %r12,%rcx
xor    %eax,%eax
call   1040 <ssystem@plt>
lea    0xe98(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <ssystem@plt>

LLVM IR (-O0):
%struct.in_addr = type { i32 }
@.str = [31 x i8] c"ifconfig %s inet `hostname` up\00"
@.str.1 = [8 x i8] c"0.0.0.0\00"
@.str.2 = [36 x i8] c"route add -net %s netmask %s dev %s\00"
@.str.3 = [13 x i8] c"ifconfig %s\0A\00"
define void @ifconf(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca %struct.in_addr
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%8 = load i8*, i8** %5
%9 = call i32 @inet_addr(i8* %8)
%10 = load i8*, i8** %6
%11 = call i32 @inet_addr(i8* %10)
%12 = and i32 %9, %11
%13 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %7, i32 0, i32 0
store i32 %12, i32* %13
%14 = load i8*, i8** %4
%15 = call i32 (i8*, i8*, ...) @ssystem(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = load i8*, i8** %5
%17 = call i64 @strcmp(i8* %16, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %28
19: ; preds = %3
%20 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %7, i32 0, i32 0
%21 = load i32, i32* %20
%22 = call i32 @inet_ntoa(i32 %21)
%23 = sext i32 %22 to i64
%24 = inttoptr i64 %23 to i8*
%25 = load i8*, i8** %6
%26 = load i8*, i8** %4
%27 = call i32 (i8*, i8*, ...) @ssystem(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %24, i8* %25, i8* %26)
br label %28
28: ; preds = %19, %3
%29 = load i8*, i8** %4
%30 = call i32 (i8*, i8*, ...) @ssystem(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %29)
ret void
}

LLVM IR (-O2):
@.str = [31 x i8] c"ifconfig %s inet `hostname` up\00"
@.str.1 = [8 x i8] c"0.0.0.0\00"
@.str.2 = [36 x i8] c"route add -net %s netmask %s dev %s\00"
@.str.3 = [13 x i8] c"ifconfig %s\0A\00"
define void @ifconf(i8* %0, i8* %1, i8* %2) {
%4 = tail call i32 @inet_addr(i8* %1)
%5 = tail call i32 @inet_addr(i8* %2)
%6 = tail call i32 (i8*, i8*, ...) @ssystem(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %0)
%7 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %15, label %9
9: ; preds = %3
%10 = and i32 %5, %4
%11 = tail call i32 @inet_ntoa(i32 %10)
%12 = sext i32 %11 to i64
%13 = inttoptr i64 %12 to i8*
%14 = tail call i32 (i8*, i8*, ...) @ssystem(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %13, i8* %2, i8* %0)
br label %15
15: ; preds = %9, %3
%16 = tail call i32 (i8*, i8*, ...) @ssystem(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %0)
ret void
}