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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ read(int, char *, int);
char *strstr(char *, char *);
void getSysVersion(char *path, char *name, char infor[]) {
  int fd = open(path, O_RDONLY);
  char store[2000];
  int k = 0;
  char *p = NULL;
  read(fd, store, sizeof(store));
  close(fd);
  p = strstr(store, name);
  while (*p != '\n' && *p != ')') {
    infor[k] = *p;
    k++;
    p++;
  }
  infor[k++] = ')';
  infor[k] = '\0';
}


x86 assembly (clang, -O0):
<getSysVersion>:
push   %rbp
mov    %rsp,%rbp
sub    $0x810,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e86(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x7f4(%rbp)
movq   $0x0,-0x800(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x7f0(%rbp),%rsi
mov    $0x7d0,%edx
call   1040 <read@plt>
mov    -0x1c(%rbp),%edi
call   1030 <close@plt>
lea    -0x7f0(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x800(%rbp)
mov    -0x800(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x801(%rbp)
je     11e5 <getSysVersion+0xa5>
mov    -0x800(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x29,%eax
setne  %al
mov    %al,-0x801(%rbp)
mov    -0x801(%rbp),%al
test   $0x1,%al
jne    11f8 <getSysVersion+0xb8>
jmp    1235 <getSysVersion+0xf5>
mov    -0x800(%rbp),%rax
mov    (%rax),%dl
mov    -0x18(%rbp),%rax
movslq -0x7f4(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x7f4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7f4(%rbp)
mov    -0x800(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x800(%rbp)
jmp    11b4 <getSysVersion+0x74>
mov    -0x18(%rbp),%rax
mov    -0x7f4(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x7f4(%rbp)
movslq %ecx,%rcx
movb   $0x29,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
movslq -0x7f4(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x810,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getSysVersion>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x7d8,%rsp
mov    %rdx,%rbx
mov    %rsi,%r14
mov    0x2e8e(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,%ebp
mov    %rsp,%r15
mov    %eax,%edi
mov    %r15,%rsi
mov    $0x7d0,%edx
call   1040 <read@plt>
mov    %ebp,%edi
call   1030 <close@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1060 <strstr@plt>
xor    %ecx,%ecx
nopl   0x0(%rax)
movzbl (%rax,%rcx,1),%edx
cmp    $0xa,%dl
je     11a7 <getSysVersion+0x67>
cmp    $0x29,%dl
je     11a7 <getSysVersion+0x67>
mov    %dl,(%rbx,%rcx,1)
add    $0x1,%rcx
jmp    1190 <getSysVersion+0x50>
mov    %ecx,%eax
add    $0x1,%ecx
movb   $0x29,(%rbx,%rax,1)
movb   $0x0,(%rbx,%rcx,1)
add    $0x7d8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
define void @getSysVersion(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca [2000 x i8]
%9 = alloca i32
%10 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%11 = load i8*, i8** %4
%12 = load i32, i32* @O_RDONLY
%13 = call i32 @open(i8* %11, i32 %12)
store i32 %13, i32* %7
store i32 0, i32* %9
store i8* null, i8** %10
%14 = load i32, i32* %7
%15 = getelementptr inbounds [2000 x i8], [2000 x i8]* %8, i64 0, i64 0
%16 = call i32 @read(i32 %14, i8* %15, i32 2000)
%17 = load i32, i32* %7
%18 = call i32 @close(i32 %17)
%19 = getelementptr inbounds [2000 x i8], [2000 x i8]* %8, i64 0, i64 0
%20 = load i8*, i8** %5
%21 = call i8* @strstr(i8* %19, i8* %20)
store i8* %21, i8** %10
br label %22
22: ; preds = %34, %3
%23 = load i8*, i8** %10
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 10
br i1 %26, label %27, label %32
27: ; preds = %22
%28 = load i8*, i8** %10
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp ne i32 %30, 41
br label %32
32: ; preds = %27, %22
%33 = phi i1 [ false, %22 ], [ %31, %27 ]
br i1 %33, label %34, label %45
34: ; preds = %32
%35 = load i8*, i8** %10
%36 = load i8, i8* %35
%37 = load i8*, i8** %6
%38 = load i32, i32* %9
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
store i8 %36, i8* %40
%41 = load i32, i32* %9
%42 = add nsw i32 %41, 1
store i32 %42, i32* %9
%43 = load i8*, i8** %10
%44 = getelementptr inbounds i8, i8* %43, i32 1
store i8* %44, i8** %10
br label %22
45: ; preds = %32
%46 = load i8*, i8** %6
%47 = load i32, i32* %9
%48 = add nsw i32 %47, 1
store i32 %48, i32* %9
%49 = sext i32 %47 to i64
%50 = getelementptr inbounds i8, i8* %46, i64 %49
store i8 41, i8* %50
%51 = load i8*, i8** %6
%52 = load i32, i32* %9
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
store i8 0, i8* %54
ret void
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
define void @getSysVersion(i8* nocapture %0, i8* nocapture %1, i8* nocapture writeonly %2) {
%4 = alloca [2000 x i8]
%5 = load i32, i32* @O_RDONLY
%6 = tail call i32 @open(i8* %0, i32 %5)
%7 = getelementptr inbounds [2000 x i8], [2000 x i8]* %4, i64 0, i64 0
%8 = call i32 @read(i32 %6, i8* %7, i32 2000)
%9 = tail call i32 @close(i32 %6)
%10 = call i8* @strstr(i8* %7, i8* dereferenceable(1) %1)
br label %11
11: ; preds = %15, %3
%12 = phi i64 [ %17, %15 ], [ 0, %3 ]
%13 = phi i8* [ %18, %15 ], [ %10, %3 ]
%14 = load i8, i8* %13
switch i8 %14, label %15 [
i8 10, label %19
i8 41, label %19
]
15: ; preds = %11
%16 = getelementptr inbounds i8, i8* %2, i64 %12
store i8 %14, i8* %16
%17 = add nuw i64 %12, 1
%18 = getelementptr inbounds i8, i8* %13, i64 1
br label %11
19: ; preds = %11, %11
%20 = add i64 %12, 1
%21 = and i64 %12, 4294967295
%22 = getelementptr inbounds i8, i8* %2, i64 %21
store i8 41, i8* %22
%23 = and i64 %20, 4294967295
%24 = getelementptr inbounds i8, i8* %2, i64 %23
store i8 0, i8* %24
ret void
}