#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*/ close(int);
int ioctl(int, unsigned long, struct ifreq *);
int /*<<< orphan*/ printf(char *);
int set_socket(struct ifreq *, char *);
int if_IOCTL(struct ifreq *if_req, unsigned long SIOC, char *name) {
  int ret;
  int sd;
  sd = set_socket(if_req, name);
  if (sd < 0) {
    return sd;
  }
  ret = ioctl(sd, SIOC, if_req);
  if (ret < 0) {
    printf("\nError on ioctl");
    return -1;
  }
  close(sd);
}


x86 assembly (clang, -O0):
<if_IOCTL>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <set_socket@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    1179 <if_IOCTL+0x39>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b6 <if_IOCTL+0x76>
mov    -0x28(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1040 <ioctl@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    11ae <if_IOCTL+0x6e>
lea    0xe63(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b6 <if_IOCTL+0x76>
mov    -0x28(%rbp),%edi
call   1050 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<if_IOCTL>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rdx,%rsi
call   1060 <set_socket@plt>
mov    %eax,%ebx
test   %eax,%eax
js     1184 <if_IOCTL+0x44>
mov    %ebx,%edi
mov    %r15,%rsi
mov    %r14,%rdx
call   1040 <ioctl@plt>
test   %eax,%eax
js     1173 <if_IOCTL+0x33>
mov    %ebx,%edi
call   1050 <close@plt>
jmp    1184 <if_IOCTL+0x44>
lea    0xe86(%rip),%rdi
call   1030 <printf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.ifreq = type { i32 }
@.str = [16 x i8] c"\0AError on ioctl\00"
define i32 @if_IOCTL(%struct.ifreq* %0, i64 %1, i8* %2) {
%4 = tail call i32 @set_socket(%struct.ifreq* %0, i8* %2)
%5 = icmp slt i32 %4, 0
br i1 %5, label %13, label %6
6: ; preds = %3
%7 = tail call i32 @ioctl(i32 %4, i64 %1, %struct.ifreq* %0)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %13
11: ; preds = %6
%12 = tail call i32 @close(i32 %4)
br label %13
13: ; preds = %3, %11, %9
%14 = phi i32 [ -1, %9 ], [ undef, %11 ], [ %4, %3 ]
ret i32 %14
}