#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 ifreq {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int close(int);
int ioctl(int, unsigned long, struct ifreq *);
int /*<<< orphan*/ perror(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int interfaceIoctl(unsigned long cmd, struct ifreq *ifr) {
  int err;
  int sock;
  if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
    perror("socket");
    return sock;
  }
  if ((err = ioctl(sock, cmd, ifr)) < 0) {
    perror("interfaceIoctl.ioctl");
    return err;
  }
  if ((err = close(sock)) < 0) {
    perror("interfaceIoctl.close");
    return err;
  }
  return 0;
}


x86 assembly (clang, -O0):
<interfaceIoctl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2e91(%rip),%rax
mov    (%rax),%edi
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jge    118c <interfaceIoctl+0x4c>
lea    0xe84(%rip),%rdi
call   1050 <perror@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11f1 <interfaceIoctl+0xb1>
mov    -0x20(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <ioctl@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    11bf <interfaceIoctl+0x7f>
lea    0xe58(%rip),%rdi
call   1050 <perror@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11f1 <interfaceIoctl+0xb1>
mov    -0x20(%rbp),%edi
call   1040 <close@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    11ea <interfaceIoctl+0xaa>
lea    0xe42(%rip),%rdi
call   1050 <perror@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11f1 <interfaceIoctl+0xb1>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<interfaceIoctl>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    0x2e96(%rip),%rax
mov    (%rax),%edi
mov    0x2e85(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %eax,%ebx
test   %eax,%eax
js     1190 <interfaceIoctl+0x50>
mov    %ebx,%edi
mov    %r15,%rsi
mov    %r14,%rdx
call   1030 <ioctl@plt>
test   %eax,%eax
js     1199 <interfaceIoctl+0x59>
mov    %ebx,%edi
call   1040 <close@plt>
xor    %ebx,%ebx
test   %eax,%eax
js     11a2 <interfaceIoctl+0x62>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe69(%rip),%rdi
jmp    11ab <interfaceIoctl+0x6b>
lea    0xe67(%rip),%rdi
jmp    11a9 <interfaceIoctl+0x69>
lea    0xe73(%rip),%rdi
mov    %eax,%ebx
call   1050 <perror@plt>
jmp    1188 <interfaceIoctl+0x48>

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

LLVM IR (-O2):
%struct.ifreq = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [7 x i8] c"socket\00"
@.str.1 = [21 x i8] c"interfaceIoctl.ioctl\00"
@.str.2 = [21 x i8] c"interfaceIoctl.close\00"
define i32 @interfaceIoctl(i64 %0, %struct.ifreq* %1) {
%3 = load i32, i32* @AF_INET
%4 = load i32, i32* @SOCK_DGRAM
%5 = tail call i32 @socket(i32 %3, i32 %4, i32 0)
%6 = icmp slt i32 %5, 0
br i1 %6, label %13, label %7
7: ; preds = %2
%8 = tail call i32 @ioctl(i32 %5, i64 %0, %struct.ifreq* %1)
%9 = icmp slt i32 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = tail call i32 @close(i32 %5)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %10, %7, %2
%14 = phi i8* [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), %7 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), %10 ]
%15 = phi i32 [ %5, %2 ], [ %8, %7 ], [ %11, %10 ]
%16 = tail call i32 @perror(i8* %14)
br label %17
17: ; preds = %13, %10
%18 = phi i32 [ 0, %10 ], [ %15, %13 ]
ret i32 %18
}