#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 KERNEL_VERSION(int, int, int);
int /*<<< orphan*/ sscanf(int /*<<< orphan*/, char *, int *, int *, int *);
int uname(struct utsname *);
int kernel_version(void) {
  int major, minor, patch;
  struct utsname buf;
  int retval = uname(&buf);
  if (retval)
    return -1;
  sscanf(buf.release, "%d.%d.%d", &major, &minor, &patch);
  return KERNEL_VERSION(major, minor, patch);
}


x86 assembly (clang, -O0):
<kernel_version>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x18(%rbp),%rdi
call   1030 <uname@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     115a <kernel_version+0x2a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1186 <kernel_version+0x56>
mov    -0x18(%rbp),%edi
lea    0xe9c(%rip),%rsi
lea    -0x8(%rbp),%rdx
lea    -0xc(%rbp),%rcx
lea    -0x10(%rbp),%r8
call   1050 <sscanf@plt>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x10(%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):
<kernel_version>:
sub    $0x18,%rsp
lea    0x8(%rsp),%rdi
call   1030 <uname@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
test   %ecx,%ecx
je     114e <kernel_version+0x1e>
add    $0x18,%rsp
ret
mov    0x8(%rsp),%edi
lea    0xea7(%rip),%rsi
lea    0x14(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0xc(%rsp),%r8
call   1050 <sscanf@plt>
mov    0x14(%rsp),%edi
mov    0x10(%rsp),%esi
mov    0xc(%rsp),%edx
call   1040 <KERNEL_VERSION@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.utsname = type { i32 }
@.str = [9 x i8] c"%d.%d.%d\00"
define i32 @kernel_version() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.utsname
%6 = alloca i32
%7 = call i32 @uname(%struct.utsname* %5)
store i32 %7, i32* %6
%8 = load i32, i32* %6
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %0
store i32 -1, i32* %1
br label %19
11: ; preds = %0
%12 = getelementptr inbounds %struct.utsname, %struct.utsname* %5, i32 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 = load i32, i32* %3
%17 = load i32, i32* %4
%18 = call i32 @KERNEL_VERSION(i32 %15, i32 %16, i32 %17)
store i32 %18, i32* %1
br label %19
19: ; preds = %11, %10
%20 = load i32, i32* %1
ret i32 %20
}

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