#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 */
typedef int uint16_t;
struct loc {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ SIOCGMIIREG;
int __phy_op(struct loc const *, int *, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stderr;
int phy_read(const struct loc *loc) {
  uint16_t val = 0;
  int err = __phy_op(loc, &val, SIOCGMIIREG);
  if (err) {
    fprintf(stderr, "error: phy_read (%d)\n", err);
    return err;
  }
  return val;
}


x86 assembly (clang, -O0):
<phy_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e9a(%rip),%rax
mov    (%rax),%edx
lea    -0x14(%rbp),%rsi
call   1030 <__phy_op@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     1179 <phy_read+0x59>
mov    0x2e83(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
lea    0xe97(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    117f <phy_read+0x5f>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<phy_read>:
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0xc(%rsp)
mov    0x2ea4(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rsi
call   1030 <__phy_op@plt>
test   %eax,%eax
je     115f <phy_read+0x3f>
mov    %eax,%ebx
mov    0x2e93(%rip),%rax
mov    (%rax),%edi
lea    0xeaa(%rip),%rsi
mov    %ebx,%edx
call   1040 <fprintf@plt>
jmp    1163 <phy_read+0x43>
mov    0xc(%rsp),%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.loc = type { i32 }
@SIOCGMIIREG = global i32 0
@stderr = global i32 0
@.str = [22 x i8] c"error: phy_read (%d)\0A\00"
define i32 @phy_read(%struct.loc* %0) {
%2 = alloca i32
%3 = alloca %struct.loc*
%4 = alloca i32
%5 = alloca i32
store %struct.loc* %0, %struct.loc** %3
store i32 0, i32* %4
%6 = load %struct.loc*, %struct.loc** %3
%7 = load i32, i32* @SIOCGMIIREG
%8 = call i32 @__phy_op(%struct.loc* %6, i32* %4, i32 %7)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = load i32, i32* %5
%14 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = load i32, i32* %5
store i32 %15, i32* %2
br label %18
16: ; preds = %1
%17 = load i32, i32* %4
store i32 %17, i32* %2
br label %18
18: ; preds = %16, %11
%19 = load i32, i32* %2
ret i32 %19
}

LLVM IR (-O2):
%struct.loc = type { i32 }
@SIOCGMIIREG = global i32 0
@stderr = global i32 0
@.str = [22 x i8] c"error: phy_read (%d)\0A\00"
define i32 @phy_read(%struct.loc* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%4 = load i32, i32* @SIOCGMIIREG
%5 = call i32 @__phy_op(%struct.loc* %0, i32* %2, i32 %4)
%6 = icmp eq i32 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %5)
br label %12
10: ; preds = %1
%11 = load i32, i32* %2
br label %12
12: ; preds = %10, %7
%13 = phi i32 [ %5, %7 ], [ %11, %10 ]
ret i32 %13
}