#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 */

/* Variables and functions */
scalar_t__ IFNAMSIZ;
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(scalar_t__);
int /*<<< orphan*/ sprintf(char *, char *, char *, int, char *);
int system(char *);
int tun_addip(char *dev, char *ip, int mask) {
  char *cmd = (char *)malloc(100 + IFNAMSIZ);
  sprintf(cmd, "ip addr add %s/%d dev %s", ip, mask, dev);
  int rc = system(cmd);
  free(cmd);
  return rc;
}


x86 assembly (clang, -O0):
<tun_addip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    0x2e86(%rip),%rax
mov    (%rax),%rdi
add    $0x64,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    -0x8(%rbp),%r8
lea    0xe80(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <system@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tun_addip>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%r15
mov    0x2e89(%rip),%rax
mov    (%rax),%rdi
add    $0x64,%rdi
call   1050 <malloc@plt>
mov    %rax,%rbp
lea    0xe93(%rip),%rsi
mov    %rax,%rdi
mov    %rbx,%rdx
mov    %r14d,%ecx
mov    %r15,%r8
call   1060 <sprintf@plt>
mov    %rbp,%rdi
call   1040 <system@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@IFNAMSIZ = global i64 0
@.str = [25 x i8] c"ip addr add %s/%d dev %s\00"
define i32 @tun_addip(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i64, i64* @IFNAMSIZ
%10 = add nsw i64 100, %9
%11 = call i64 @malloc(i64 %10)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %7
%13 = load i8*, i8** %7
%14 = load i8*, i8** %5
%15 = load i32, i32* %6
%16 = load i8*, i8** %4
%17 = call i32 @sprintf(i8* %13, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %14, i32 %15, i8* %16)
%18 = load i8*, i8** %7
%19 = call i32 @system(i8* %18)
store i32 %19, i32* %8
%20 = load i8*, i8** %7
%21 = call i32 @free(i8* %20)
%22 = load i32, i32* %8
ret i32 %22
}

LLVM IR (-O2):
@IFNAMSIZ = global i64 0
@.str = [25 x i8] c"ip addr add %s/%d dev %s\00"
define i32 @tun_addip(i8* %0, i8* %1, i32 %2) {
%4 = load i64, i64* @IFNAMSIZ
%5 = add nsw i64 %4, 100
%6 = tail call i64 @malloc(i64 %5)
%7 = inttoptr i64 %6 to i8*
%8 = tail call i32 @sprintf(i8* dereferenceable(1) %7, i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %1, i32 %2, i8* %0)
%9 = tail call i32 @system(i8* %7)
%10 = tail call i32 @free(i8* %7)
ret i32 %9
}