#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 utsname {
  int /*<<< orphan*/ release;
};

/* Variables and functions */
int ENOSYS;
int KERNEL_VERSION(unsigned int, unsigned int, unsigned int);
int errno;
int sscanf(int /*<<< orphan*/, char *, unsigned int *, unsigned int *,
           unsigned int *);
int uname(struct utsname *);
int tapdisk_linux_version(void) {
  struct utsname uts;
  unsigned int version, patchlevel, sublevel;
  int n, err;
  err = uname(&uts);
  if (err)
    return -errno;
  n = sscanf(uts.release, "%u.%u.%u", &version, &patchlevel, &sublevel);
  if (n != 3)
    return -ENOSYS;
  return KERNEL_VERSION(version, patchlevel, sublevel);
}


x86 assembly (clang, -O0):
<tapdisk_linux_version>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x8(%rbp),%rdi
call   1030 <uname@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1161 <tapdisk_linux_version+0x31>
xor    %eax,%eax
mov    0x2e81(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11ad <tapdisk_linux_version+0x7d>
mov    -0x8(%rbp),%edi
lea    0xe95(%rip),%rsi
lea    -0xc(%rbp),%rdx
lea    -0x10(%rbp),%rcx
lea    -0x14(%rbp),%r8
call   1050 <sscanf@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x3,-0x18(%rbp)
je     119c <tapdisk_linux_version+0x6c>
xor    %eax,%eax
mov    0x2e56(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11ad <tapdisk_linux_version+0x7d>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1040 <KERNEL_VERSION@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tapdisk_linux_version>:
sub    $0x18,%rsp
lea    0x8(%rsp),%rdi
call   1030 <uname@plt>
test   %eax,%eax
je     114b <tapdisk_linux_version+0x1b>
mov    0x2e8f(%rip),%rcx
jmp    118c <tapdisk_linux_version+0x5c>
mov    0x8(%rsp),%edi
lea    0xeaa(%rip),%rsi
lea    0x14(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0xc(%rsp),%r8
call   1050 <sscanf@plt>
cmp    $0x3,%eax
jne    1185 <tapdisk_linux_version+0x55>
mov    0x14(%rsp),%edi
mov    0x10(%rsp),%esi
mov    0xc(%rsp),%edx
call   1040 <KERNEL_VERSION@plt>
add    $0x18,%rsp
ret
mov    0x2e5c(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.utsname = type { i32 }
@errno = global i32 0
@.str = [9 x i8] c"%u.%u.%u\00"
@ENOSYS = global i32 0
define i32 @tapdisk_linux_version() {
%1 = alloca i32
%2 = alloca %struct.utsname
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = call i32 @uname(%struct.utsname* %2)
store i32 %8, i32* %7
%9 = load i32, i32* %7
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %0
%12 = load i32, i32* @errno
%13 = sub nsw i32 0, %12
store i32 %13, i32* %1
br label %28
14: ; preds = %0
%15 = getelementptr inbounds %struct.utsname, %struct.utsname* %2, i32 0, i32 0
%16 = load i32, i32* %15
%17 = call i32 @sscanf(i32 %16, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %3, i32* %4, i32* %5)
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = icmp ne i32 %18, 3
br i1 %19, label %20, label %23
20: ; preds = %14
%21 = load i32, i32* @ENOSYS
%22 = sub nsw i32 0, %21
store i32 %22, i32* %1
br label %28
23: ; preds = %14
%24 = load i32, i32* %3
%25 = load i32, i32* %4
%26 = load i32, i32* %5
%27 = call i32 @KERNEL_VERSION(i32 %24, i32 %25, i32 %26)
store i32 %27, i32* %1
br label %28
28: ; preds = %23, %20, %11
%29 = load i32, i32* %1
ret i32 %29
}

LLVM IR (-O2):
%struct.utsname = type { i32 }
@errno = global i32 0
@.str = [9 x i8] c"%u.%u.%u\00"
@ENOSYS = global i32 0
define i32 @tapdisk_linux_version() {
%1 = alloca %struct.utsname
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = bitcast %struct.utsname* %1 to i8*
%6 = bitcast i32* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = call i32 @uname(%struct.utsname* %1)
%10 = icmp eq i32 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %0
%12 = load i32, i32* @errno
%13 = sub nsw i32 0, %12
br label %27
14: ; preds = %0
%15 = getelementptr inbounds %struct.utsname, %struct.utsname* %1, i64 0, i32 0
%16 = load i32, i32* %15
%17 = call i32 @sscanf(i32 %16, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %2, i32* %3, i32* %4)
%18 = icmp eq i32 %17, 3
br i1 %18, label %22, label %19
19: ; preds = %14
%20 = load i32, i32* @ENOSYS
%21 = sub nsw i32 0, %20
br label %27
22: ; preds = %14
%23 = load i32, i32* %2
%24 = load i32, i32* %3
%25 = load i32, i32* %4
%26 = call i32 @KERNEL_VERSION(i32 %23, i32 %24, i32 %25)
br label %27
27: ; preds = %22, %19, %11
%28 = phi i32 [ %13, %11 ], [ %21, %19 ], [ %26, %22 ]
ret i32 %28
}