#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*/ version;
};

/* Variables and functions */
int /*<<< orphan*/ sscanf(int /*<<< orphan*/, char *, int *, int *, int *);
int uname(struct utsname *);
int __get_linux_kernel_version(void) {
  struct utsname name;
  int major = 0, minor = 0, patch = 0;
  if (uname(&name) == -1) {
    return (0);
  }
  sscanf(name.version, "%d.%d.%d", &major, &minor, &patch);
  return major * 65536 + minor * 256 + patch;
}


x86 assembly (clang, -O0):
<__get_linux_kernel_version>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    -0x8(%rbp),%rdi
call   1030 <uname@plt>
cmp    $0xffffffff,%eax
jne    115b <__get_linux_kernel_version+0x3b>
movl   $0x0,-0x4(%rbp)
jmp    118a <__get_linux_kernel_version+0x6a>
mov    -0x8(%rbp),%edi
lea    0xe9b(%rip),%rsi
lea    -0xc(%rbp),%rdx
lea    -0x10(%rbp),%rcx
lea    -0x14(%rbp),%r8
call   1040 <sscanf@plt>
mov    -0xc(%rbp),%eax
shl    $0x10,%eax
mov    -0x10(%rbp),%ecx
shl    $0x8,%ecx
add    %ecx,%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__get_linux_kernel_version>:
sub    $0x18,%rsp
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
movl   $0x0,0x4(%rsp)
lea    0x10(%rsp),%rdi
call   1030 <uname@plt>
cmp    $0xffffffff,%eax
je     1183 <__get_linux_kernel_version+0x63>
mov    0x10(%rsp),%edi
lea    0xeaa(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
lea    0x4(%rsp),%r8
call   1040 <sscanf@plt>
mov    0xc(%rsp),%ecx
shl    $0x10,%ecx
mov    0x8(%rsp),%eax
shl    $0x8,%eax
add    %ecx,%eax
add    0x4(%rsp),%eax
add    $0x18,%rsp
ret
xor    %eax,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.utsname = type { i32 }
@.str = [9 x i8] c"%d.%d.%d\00"
define i32 @__get_linux_kernel_version() {
%1 = alloca i32
%2 = alloca %struct.utsname
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
%6 = call i32 @uname(%struct.utsname* %2)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %9
8: ; preds = %0
store i32 0, i32* %1
br label %20
9: ; preds = %0
%10 = getelementptr inbounds %struct.utsname, %struct.utsname* %2, i32 0, i32 0
%11 = load i32, i32* %10
%12 = call i32 @sscanf(i32 %11, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %3, i32* %4, i32* %5)
%13 = load i32, i32* %3
%14 = mul nsw i32 %13, 65536
%15 = load i32, i32* %4
%16 = mul nsw i32 %15, 256
%17 = add nsw i32 %14, %16
%18 = load i32, i32* %5
%19 = add nsw i32 %17, %18
store i32 %19, i32* %1
br label %20
20: ; preds = %9, %8
%21 = load i32, i32* %1
ret i32 %21
}

LLVM IR (-O2):
%struct.utsname = type { i32 }
@.str = [9 x i8] c"%d.%d.%d\00"
define i32 @__get_linux_kernel_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*
store i32 0, i32* %2
%7 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%8 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%9 = call i32 @uname(%struct.utsname* %1)
%10 = icmp eq i32 %9, -1
br i1 %10, label %22, label %11
11: ; preds = %0
%12 = getelementptr inbounds %struct.utsname, %struct.utsname* %1, i64 0, i32 0
%13 = load i32, i32* %12
%14 = call i32 @sscanf(i32 %13, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %2, i32* %3, i32* %4)
%15 = load i32, i32* %2
%16 = shl nsw i32 %15, 16
%17 = load i32, i32* %3
%18 = shl nsw i32 %17, 8
%19 = add nsw i32 %18, %16
%20 = load i32, i32* %4
%21 = add nsw i32 %19, %20
br label %22
22: ; preds = %0, %11
%23 = phi i32 [ %21, %11 ], [ 0, %0 ]
ret i32 %23
}