#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ *fopen(char *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ isdigit(char);
int /*<<< orphan*/ memmove(char *, char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
char *strchr(char *, char);
void get_os(char *buffer) {
  int i, n, m;
  memset(buffer, 0, 1024);
  FILE *f = fopen("/proc/version", "r");
  n = fread(buffer, 1, 1024, f);
  m = strchr(strchr(buffer, ' ') + 1, ' ') - buffer + 1;
  memmove(buffer, buffer + m, n - m);
  for (i = 0;; i++) {
    if (!isdigit(buffer[i]) && buffer[i] != '.') {
      buffer[i] = '\0';
      return;
    }
  }
}


x86 assembly (clang, -O0):
<get_os>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
lea    0xe7d(%rip),%rdi
lea    0xe84(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x400,%edx
call   1040 <fread@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x20,%esi
call   1050 <strchr@plt>
mov    %rax,%rdi
add    $0x1,%rdi
mov    $0x20,%esi
call   1050 <strchr@plt>
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0x14(%rbp),%rax
add    %rax,%rsi
mov    -0x10(%rbp),%edx
sub    -0x14(%rbp),%edx
call   1070 <memmove@plt>
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    123c <get_os+0xdc>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
je     123c <get_os+0xdc>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret
jmp    1241 <get_os+0xe1>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11fb <get_os+0x9b>

x86 assembly (clang, -O2):
<get_os>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
lea    0xe87(%rip),%rdi
lea    0xe8e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    $0x20,%esi
call   1050 <strchr@plt>
lea    0x1(%rax),%rdi
mov    $0x20,%esi
call   1050 <strchr@plt>
sub    %ebx,%eax
add    $0x1,%eax
cltq
lea    (%rbx,%rax,1),%rsi
sub    %eax,%ebp
mov    %rbx,%rdi
mov    %ebp,%edx
call   1070 <memmove@plt>
jmp    11d4 <get_os+0x74>
add    $0x1,%rbx
movsbl (%rbx),%edi
call   1030 <isdigit@plt>
test   %eax,%eax
jne    11d0 <get_os+0x70>
cmpb   $0x2e,(%rbx)
je     11d0 <get_os+0x70>
movb   $0x0,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/version\00"
@.str.1 = [2 x i8] c"r\00"
define void @get_os(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i32 @memset(i8* %7, i32 0, i32 1024)
%9 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %6
%10 = load i8*, i8** %2
%11 = load i32*, i32** %6
%12 = call i32 @fread(i8* %10, i32 1, i32 1024, i32* %11)
store i32 %12, i32* %4
%13 = load i8*, i8** %2
%14 = call i8* @strchr(i8* %13, i8 signext 32)
%15 = getelementptr inbounds i8, i8* %14, i64 1
%16 = call i8* @strchr(i8* %15, i8 signext 32)
%17 = load i8*, i8** %2
%18 = ptrtoint i8* %16 to i64
%19 = ptrtoint i8* %17 to i64
%20 = sub i64 %18, %19
%21 = add nsw i64 %20, 1
%22 = trunc i64 %21 to i32
store i32 %22, i32* %5
%23 = load i8*, i8** %2
%24 = load i8*, i8** %2
%25 = load i32, i32* %5
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i32, i32* %4
%29 = load i32, i32* %5
%30 = sub nsw i32 %28, %29
%31 = call i32 @memmove(i8* %23, i8* %27, i32 %30)
store i32 0, i32* %3
br label %32
32: ; preds = %54, %1
%33 = load i8*, i8** %2
%34 = load i32, i32* %3
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = load i8, i8* %36
%38 = call i32 @isdigit(i8 signext %37)
%39 = icmp ne i32 %38, 0
br i1 %39, label %53, label %40
40: ; preds = %32
%41 = load i8*, i8** %2
%42 = load i32, i32* %3
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp ne i32 %46, 46
br i1 %47, label %48, label %53
48: ; preds = %40
%49 = load i8*, i8** %2
%50 = load i32, i32* %3
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %49, i64 %51
store i8 0, i8* %52
ret void
53: ; preds = %40, %32
br label %54
54: ; preds = %53
%55 = load i32, i32* %3
%56 = add nsw i32 %55, 1
store i32 %56, i32* %3
br label %32
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/version\00"
@.str.1 = [2 x i8] c"r\00"
define void @get_os(i8* %0) {
%2 = tail call i32 @memset(i8* %0, i32 0, i32 1024)
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i32 @fread(i8* %0, i32 1, i32 1024, i32* %3)
%5 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 32)
%6 = getelementptr inbounds i8, i8* %5, i64 1
%7 = tail call i8* @strchr(i8* %6, i8 signext 32)
%8 = ptrtoint i8* %7 to i64
%9 = ptrtoint i8* %0 to i64
%10 = sub i64 %8, %9
%11 = trunc i64 %10 to i32
%12 = add i32 %11, 1
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = sub nsw i32 %4, %12
%16 = tail call i32 @memmove(i8* %0, i8* %14, i32 %15)
br label %17
17: ; preds = %27, %1
%18 = phi i64 [ %28, %27 ], [ 0, %1 ]
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = load i8, i8* %19
%21 = tail call i32 @isdigit(i8 signext %20)
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %17
%24 = load i8, i8* %19
%25 = icmp eq i8 %24, 46
br i1 %25, label %27, label %26
26: ; preds = %23
store i8 0, i8* %19
ret void
27: ; preds = %17, %23
%28 = add nuw i64 %18, 1
br label %17
}