#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 {
  scalar_t__ ifr_data;
  int /*<<< orphan*/ ifr_name;
};
struct hwtstamp_config {
  int tx_type;
  int rx_filter;
  scalar_t__ flags;
};
typedef scalar_t__ caddr_t;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SIOCSHWTSTAMP;
int /*<<< orphan*/ SOCK_DGRAM;
scalar_t__ ioctl(int, int /*<<< orphan*/, struct ifreq *);
int /*<<< orphan*/ perror(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char const *);
int hwtstamp_config_set(const char *ifname, int tx_type, int rx_filter) {
  struct hwtstamp_config config;
  int sock, ret = 0;
  struct ifreq ifr;
  sock = socket(AF_INET, SOCK_DGRAM, 0);
  if (sock < 0) {
    perror("socket");
    ret = -1;
    goto out;
  }
  config.flags = 0;
  config.tx_type = tx_type;
  config.rx_filter = rx_filter;
  strcpy(ifr.ifr_name, ifname);
  ifr.ifr_data = (caddr_t)&config;
  if (ioctl(sock, SIOCSHWTSTAMP, &ifr)) {
    perror("ioctl");
    ret = -1;
    goto out;
  }
out:
  return ret;
}


x86 assembly (clang, -O0):
<hwtstamp_config_set>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x28(%rbp)
mov    0x2e88(%rip),%rax
mov    (%rax),%edi
mov    0x2e77(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1197 <hwtstamp_config_set+0x57>
lea    0xe7a(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x28(%rbp)
jmp    11fb <hwtstamp_config_set+0xbb>
movq   $0x0,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x30(%rbp),%edi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x24(%rbp),%edi
mov    0x2e07(%rip),%rax
mov    (%rax),%esi
lea    -0x38(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
je     11f6 <hwtstamp_config_set+0xb6>
lea    0xe22(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x28(%rbp)
jmp    11fb <hwtstamp_config_set+0xbb>
jmp    11fb <hwtstamp_config_set+0xbb>
mov    -0x28(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hwtstamp_config_set>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %edx,%r12d
mov    %esi,%ebx
mov    %rdi,%r15
mov    0x2e8d(%rip),%rax
mov    (%rax),%edi
mov    0x2e7c(%rip),%rax
mov    (%rax),%esi
xor    %r14d,%r14d
xor    %edx,%edx
call   1060 <socket@plt>
test   %eax,%eax
js     11c1 <hwtstamp_config_set+0x81>
mov    %eax,%ebp
movq   $0x0,0x8(%rsp)
mov    %ebx,(%rsp)
mov    %r12d,0x4(%rsp)
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %rsp,%rax
mov    %rax,0x10(%rsp)
mov    0x2e32(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdx
mov    %ebp,%edi
call   1040 <ioctl@plt>
test   %rax,%rax
jne    11ca <hwtstamp_config_set+0x8a>
mov    %r14d,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe38(%rip),%rdi
jmp    11d1 <hwtstamp_config_set+0x91>
lea    0xe36(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%r14d
jmp    11b1 <hwtstamp_config_set+0x71>

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

LLVM IR (-O2):
%struct.hwtstamp_config = type { i32, i32, i64 }
%struct.ifreq = type { i64, i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [7 x i8] c"socket\00"
@SIOCSHWTSTAMP = global i32 0
@.str.1 = [6 x i8] c"ioctl\00"
define i32 @hwtstamp_config_set(i8* %0, i32 %1, i32 %2) {
%4 = alloca %struct.hwtstamp_config
%5 = alloca %struct.ifreq
%6 = bitcast %struct.hwtstamp_config* %4 to i8*
%7 = bitcast %struct.ifreq* %5 to i8*
%8 = load i32, i32* @AF_INET
%9 = load i32, i32* @SOCK_DGRAM
%10 = tail call i32 @socket(i32 %8, i32 %9, i32 0)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %3
%13 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %26
14: ; preds = %3
%15 = getelementptr inbounds %struct.hwtstamp_config, %struct.hwtstamp_config* %4, i64 0, i32 2
store i64 0, i64* %15
%16 = getelementptr inbounds %struct.hwtstamp_config, %struct.hwtstamp_config* %4, i64 0, i32 0
store i32 %1, i32* %16
%17 = getelementptr inbounds %struct.hwtstamp_config, %struct.hwtstamp_config* %4, i64 0, i32 1
store i32 %2, i32* %17
%18 = tail call i32 @strcpy(i32 undef, i8* %0)
%19 = ptrtoint %struct.hwtstamp_config* %4 to i64
%20 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %5, i64 0, i32 0
store i64 %19, i64* %20
%21 = load i32, i32* @SIOCSHWTSTAMP
%22 = call i64 @ioctl(i32 %10, i32 %21, %struct.ifreq* %5)
%23 = icmp eq i64 %22, 0
br i1 %23, label %26, label %24
24: ; preds = %14
%25 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %14, %24, %12
%27 = phi i32 [ -1, %12 ], [ -1, %24 ], [ 0, %14 ]
ret i32 %27
}