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

/* Variables and functions */
int /*<<< orphan*/ ETHTOOL_GDRVINFO;
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 = ETHTOOL_GDRVINFO;
  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>
mov    0x2e85(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <ethtool_ioctl@plt>
cmp    $0x0,%rax
je     117c <ethtool_driver+0x4c>
movq   $0x0,-0x8(%rbp)
jmp    1188 <ethtool_driver+0x58>
mov    -0x18(%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>
mov    0x2e7e(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <ethtool_ioctl@plt>
test   %rax,%rax
jne    117c <ethtool_driver+0x4c>
mov    0x8(%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 }
@ETHTOOL_GDRVINFO = global i32 0
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 = load i32, i32* @ETHTOOL_GDRVINFO
%7 = getelementptr inbounds %struct.ethtool_drvinfo, %struct.ethtool_drvinfo* %4, i32 0, i32 1
store i32 %6, i32* %7
%8 = load i8*, i8** %3
%9 = call i64 @ethtool_ioctl(i8* %8, %struct.ethtool_drvinfo* %4)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %1
store i8* null, i8** %2
br label %16
12: ; preds = %1
%13 = getelementptr inbounds %struct.ethtool_drvinfo, %struct.ethtool_drvinfo* %4, i32 0, i32 0
%14 = load i32, i32* %13
%15 = call i8* @strdup(i32 %14)
store i8* %15, i8** %2
br label %16
16: ; preds = %12, %11
%17 = load i8*, i8** %2
ret i8* %17
}

LLVM IR (-O2):
%struct.ethtool_drvinfo = type { i32, i32 }
@ETHTOOL_GDRVINFO = global i32 0
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 = load i32, i32* @ETHTOOL_GDRVINFO
%6 = getelementptr inbounds %struct.ethtool_drvinfo, %struct.ethtool_drvinfo* %2, i64 0, i32 1
store i32 %5, i32* %6
%7 = call i64 @ethtool_ioctl(i8* %0, %struct.ethtool_drvinfo* %2)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %1
%10 = getelementptr inbounds %struct.ethtool_drvinfo, %struct.ethtool_drvinfo* %2, i64 0, i32 0
%11 = load i32, i32* %10
%12 = call i8* @strdup(i32 %11)
br label %13
13: ; preds = %1, %9
%14 = phi i8* [ %12, %9 ], [ null, %1 ]
ret i8* %14
}