#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 */
typedef int /*<<< orphan*/ uint32_t;
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct ifreq {
  int /*<<< orphan*/ ifr_addr;
  int /*<<< orphan*/ ifr_name;
};
typedef int /*<<< orphan*/ ifr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ IFNAMSIZ;
int /*<<< orphan*/ SIOCSIFADDR;
int interfaceIoctl(int /*<<< orphan*/, struct ifreq *);
int /*<<< orphan*/ memset(struct ifreq *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char const *,
                           int /*<<< orphan*/);
int tunSetIp(const char *dev, uint32_t inetAddr) {
  struct ifreq ifr;
  int err;
  memset(&ifr, 0, sizeof(ifr));
  ;
  strncpy(ifr.ifr_name, dev, IFNAMSIZ);
  struct sockaddr_in *sin;
  sin = (struct sockaddr_in *)&ifr.ifr_addr;
  sin->sin_family = AF_INET;
  sin->sin_addr.s_addr = inetAddr;
  if ((err = interfaceIoctl(SIOCSIFADDR, &ifr)) < 0) {
    perror("tunSetIp"
           ": ioctl set s_addr");
    return err;
  }
  return 0;
}


x86 assembly (clang, -O0):
<tunSetIp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    0x2e6b(%rip),%rax
mov    (%rax),%edx
call   1030 <strncpy@plt>
lea    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    0x2e65(%rip),%rax
mov    (%rax),%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x14(%rbp),%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
call   1060 <interfaceIoctl@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jge    11ca <tunSetIp+0x8a>
lea    0xe46(%rip),%rdi
call   1050 <perror@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d1 <tunSetIp+0x91>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tunSetIp>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
mov    %rsp,%r15
xor    %r14d,%r14d
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    0x4(%rsp),%edi
mov    0x2e6c(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rsi
call   1030 <strncpy@plt>
mov    0x2e6b(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    %ebp,(%rsp)
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
mov    %r15,%rsi
call   1060 <interfaceIoctl@plt>
test   %eax,%eax
js     11a9 <tunSetIp+0x69>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%ebp
lea    0xe4e(%rip),%rdi
call   1050 <perror@plt>
mov    %ebp,%r14d
jmp    119b <tunSetIp+0x5b>

LLVM IR (-O0):
%struct.ifreq = type { i32, i32 }
%struct.sockaddr_in = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
@IFNAMSIZ = global i32 0
@AF_INET = global i32 0
@SIOCSIFADDR = global i32 0
@.str = [27 x i8] c"tunSetIp: ioctl set s_addr\00"
define i32 @tunSetIp(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca %struct.ifreq
%7 = alloca i32
%8 = alloca %struct.sockaddr_in*
store i8* %0, i8** %4
store i32 %1, i32* %5
%9 = call i32 @memset(%struct.ifreq* %6, i32 0, i32 8)
%10 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %6, i32 0, i32 1
%11 = load i32, i32* %10
%12 = load i8*, i8** %4
%13 = load i32, i32* @IFNAMSIZ
%14 = call i32 @strncpy(i32 %11, i8* %12, i32 %13)
%15 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %6, i32 0, i32 0
%16 = bitcast i32* %15 to %struct.sockaddr_in*
store %struct.sockaddr_in* %16, %struct.sockaddr_in** %8
%17 = load i32, i32* @AF_INET
%18 = load %struct.sockaddr_in*, %struct.sockaddr_in** %8
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %18, i32 0, i32 1
store i32 %17, i32* %19
%20 = load i32, i32* %5
%21 = load %struct.sockaddr_in*, %struct.sockaddr_in** %8
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %21, i32 0, i32 0
%23 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %22, i32 0, i32 0
store i32 %20, i32* %23
%24 = load i32, i32* @SIOCSIFADDR
%25 = call i32 @interfaceIoctl(i32 %24, %struct.ifreq* %6)
store i32 %25, i32* %7
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %2
%28 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%29 = load i32, i32* %7
store i32 %29, i32* %3
br label %31
30: ; preds = %2
store i32 0, i32* %3
br label %31
31: ; preds = %30, %27
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
%struct.ifreq = type { i32, i32 }
@IFNAMSIZ = global i32 0
@AF_INET = global i32 0
@SIOCSIFADDR = global i32 0
@.str = [27 x i8] c"tunSetIp: ioctl set s_addr\00"
define i32 @tunSetIp(i8* %0, i32 %1) {
%3 = alloca %struct.ifreq
%4 = bitcast %struct.ifreq* %3 to i8*
%5 = call i32 @memset(%struct.ifreq* %3, i32 0, i32 8)
%6 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i64 0, i32 1
%7 = load i32, i32* %6
%8 = load i32, i32* @IFNAMSIZ
%9 = call i32 @strncpy(i32 %7, i8* %0, i32 %8)
%10 = load i32, i32* @AF_INET
store i32 %10, i32* %6
%11 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i64 0, i32 0
store i32 %1, i32* %11
%12 = load i32, i32* @SIOCSIFADDR
%13 = call i32 @interfaceIoctl(i32 %12, %struct.ifreq* %3)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %2, %15
%18 = phi i32 [ %13, %15 ], [ 0, %2 ]
ret i32 %18
}