#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;
};
typedef scalar_t__ caddr_t;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SIOCGHWTSTAMP;
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_get(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;
  }
  strcpy(ifr.ifr_name, ifname);
  ifr.ifr_data = (caddr_t)&config;
  if (ioctl(sock, SIOCGHWTSTAMP, &ifr)) {
    perror("ioctl");
    ret = -1;
    goto out;
  }
  *tx_type = config.tx_type;
  *rx_filter = config.rx_filter;
out:
  return ret;
}


x86 assembly (clang, -O0):
<hwtstamp_config_get>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x28(%rbp)
mov    0x2e7e(%rip),%rax
mov    (%rax),%edi
mov    0x2e6d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1199 <hwtstamp_config_get+0x59>
lea    0xe78(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x28(%rbp)
jmp    11f6 <hwtstamp_config_get+0xb6>
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    0x2e41(%rip),%rax
mov    (%rax),%esi
lea    -0x38(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
je     11e4 <hwtstamp_config_get+0xa4>
lea    0xe34(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x28(%rbp)
jmp    11f6 <hwtstamp_config_get+0xb6>
mov    -0x20(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hwtstamp_config_get>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    0x2e86(%rip),%rax
mov    (%rax),%edi
mov    0x2e75(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
test   %eax,%eax
js     11b6 <hwtstamp_config_get+0x76>
mov    %eax,%ebp
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %rsp,%rax
mov    %rax,0x8(%rsp)
mov    0x2e6f(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebp,%edi
call   1040 <ioctl@plt>
test   %rax,%rax
jne    11bf <hwtstamp_config_get+0x7f>
mov    (%rsp),%eax
mov    %eax,(%r15)
mov    0x4(%rsp),%eax
mov    %eax,(%r14)
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe43(%rip),%rdi
jmp    11c6 <hwtstamp_config_get+0x86>
lea    0xe41(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%eax
jmp    11ab <hwtstamp_config_get+0x6b>

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

LLVM IR (-O2):
%struct.hwtstamp_config = type { i32, i32 }
%struct.ifreq = type { i64, i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [7 x i8] c"socket\00"
@SIOCGHWTSTAMP = global i32 0
@.str.1 = [6 x i8] c"ioctl\00"
define i32 @hwtstamp_config_get(i8* %0, i32* nocapture writeonly %1, i32* nocapture writeonly %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 %28
14: ; preds = %3
%15 = tail call i32 @strcpy(i32 undef, i8* %0)
%16 = ptrtoint %struct.hwtstamp_config* %4 to i64
%17 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %5, i64 0, i32 0
store i64 %16, i64* %17
%18 = load i32, i32* @SIOCGHWTSTAMP
%19 = call i64 @ioctl(i32 %10, i32 %18, %struct.ifreq* %5)
%20 = icmp eq i64 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %14
%22 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %28
23: ; preds = %14
%24 = getelementptr inbounds %struct.hwtstamp_config, %struct.hwtstamp_config* %4, i64 0, i32 0
%25 = load i32, i32* %24
store i32 %25, i32* %1
%26 = getelementptr inbounds %struct.hwtstamp_config, %struct.hwtstamp_config* %4, i64 0, i32 1
%27 = load i32, i32* %26
store i32 %27, i32* %2
br label %28
28: ; preds = %23, %21, %12
%29 = phi i32 [ -1, %12 ], [ -1, %21 ], [ 0, %23 ]
ret i32 %29
}