#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 ethtool_drvinfo {
  int cmd;
  int /*<<< orphan*/ driver;
};
typedef int /*<<< orphan*/ info;

/* Variables and functions */
scalar_t__ ethtool_ioctl(char const *, struct ethtool_drvinfo *);
int /*<<< orphan*/ memset(struct ethtool_drvinfo *, int /*<<< orphan*/, int);
char *strdup(int /*<<< orphan*/);
char *ethtool_driver(const char *ifname) {
  struct ethtool_drvinfo info;
  memset(&info, 0, sizeof(info));
  info.cmd = 0x00000003;
  if (ethtool_ioctl(ifname, &info))
    return NULL;
  return strdup(info.driver);
}


x86 assembly (clang, -O0):
<ethtool_driver>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
movl   $0x3,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <ethtool_ioctl@plt>
cmp    $0x0,%rax
je     1177 <ethtool_driver+0x47>
movq   $0x0,-0x8(%rbp)
jmp    1183 <ethtool_driver+0x53>
mov    -0x14(%rbp),%edi
call   1050 <strdup@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ethtool_driver>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%r15
xor    %r14d,%r14d
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
movl   $0x3,0x8(%rsp)
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <ethtool_ioctl@plt>
test   %rax,%rax
jne    1177 <ethtool_driver+0x47>
mov    0xc(%rsp),%edi
call   1050 <strdup@plt>
mov    %rax,%r14
mov    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.ethtool_drvinfo = type { i32, i32 }
define i8* @ethtool_driver(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca %struct.ethtool_drvinfo
store i8* %0, i8** %3
%5 = call i32 @memset(%struct.ethtool_drvinfo* %4, i32 0, i32 8)
%6 = getelementptr inbounds %struct.ethtool_drvinfo, %struct.ethtool_drvinfo* %4, i32 0, i32 0
store i32 3, i32* %6
%7 = load i8*, i8** %3
%8 = call i64 @ethtool_ioctl(i8* %7, %struct.ethtool_drvinfo* %4)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %1
store i8* null, i8** %2
br label %15
11: ; preds = %1
%12 = getelementptr inbounds %struct.ethtool_drvinfo, %struct.ethtool_drvinfo* %4, i32 0, i32 1
%13 = load i32, i32* %12
%14 = call i8* @strdup(i32 %13)
store i8* %14, i8** %2
br label %15
15: ; preds = %11, %10
%16 = load i8*, i8** %2
ret i8* %16
}

LLVM IR (-O2):
%struct.ethtool_drvinfo = type { i32, i32 }
define i8* @ethtool_driver(i8* %0) {
%2 = alloca %struct.ethtool_drvinfo
%3 = bitcast %struct.ethtool_drvinfo* %2 to i8*
%4 = call i32 @memset(%struct.ethtool_drvinfo* %2, i32 0, i32 8)
%5 = getelementptr inbounds %struct.ethtool_drvinfo, %struct.ethtool_drvinfo* %2, i64 0, i32 0
store i32 3, i32* %5
%6 = call i64 @ethtool_ioctl(i8* %0, %struct.ethtool_drvinfo* %2)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = getelementptr inbounds %struct.ethtool_drvinfo, %struct.ethtool_drvinfo* %2, i64 0, i32 1
%10 = load i32, i32* %9
%11 = call i8* @strdup(i32 %10)
br label %12
12: ; preds = %1, %8
%13 = phi i8* [ %11, %8 ], [ null, %1 ]
ret i8* %13
}