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

/* Variables and functions */
int /*<<< orphan*/ FileProxy_ReadFile(char *, char *, unsigned int);
int Utils_StrChr(char *, int, int, char);
int Utils_StrFind(char *, int, int, char *);
int /*<<< orphan*/ memcpy(char *, char *, size_t);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int strlen(char *);
int FileProxy_ReadVersionCHeader(char *filename, char *verstr, char *vername) {
  char buf[(1024U)] = {0};
  int lpos;
  int rpos;
  int len;
  char defstr[100] = {0};
  if ((vername == NULL) || (*vername == 0)) {
    vername = ("VERSION");
  }
  sprintf(&defstr[0], "#define  %s", vername);
  FileProxy_ReadFile(filename, buf, (1024U));
  len = strlen(buf) + 1;
  lpos = Utils_StrFind(buf, 1, len, defstr);
  lpos = Utils_StrChr(buf, lpos + 1, len, '"');
  rpos = Utils_StrChr(buf, lpos + 1, len, '"');
  memcpy(verstr, &buf[lpos], (size_t)(rpos - lpos - 1));
  return (0);
}


x86 assembly (clang, -O0):
<FileProxy_ReadVersionCHeader>:
push   %rbp
mov    %rsp,%rbp
sub    $0x490,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
lea    -0x490(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1050 <memset@plt>
cmpq   $0x0,-0x18(%rbp)
je     11c8 <FileProxy_ReadVersionCHeader+0x58>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11d3 <FileProxy_ReadVersionCHeader+0x63>
lea    0xe31(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    -0x490(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe23(%rip),%rsi
call   1090 <sprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1060 <FileProxy_ReadFile@plt>
lea    -0x420(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x42c(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x42c(%rbp),%edx
lea    -0x490(%rbp),%rcx
mov    $0x1,%esi
call   1030 <Utils_StrFind@plt>
mov    %eax,-0x424(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x424(%rbp),%esi
add    $0x1,%esi
mov    -0x42c(%rbp),%edx
mov    $0x22,%ecx
call   1080 <Utils_StrChr@plt>
mov    %eax,-0x424(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x424(%rbp),%esi
add    $0x1,%esi
mov    -0x42c(%rbp),%edx
mov    $0x22,%ecx
call   1080 <Utils_StrChr@plt>
mov    %eax,-0x428(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x424(%rbp),%rax
lea    -0x420(%rbp),%rsi
add    %rax,%rsi
mov    -0x428(%rbp),%eax
sub    -0x424(%rbp),%eax
sub    $0x1,%eax
movslq %eax,%rdx
call   1070 <memcpy@plt>
xor    %eax,%eax
add    $0x490,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FileProxy_ReadVersionCHeader>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x478,%rsp
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
lea    0x70(%rsp),%rdi
mov    $0x400,%edx
xor    %esi,%esi
call   1050 <memset@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movl   $0x0,0x60(%rsp)
test   %rbx,%rbx
je     11cd <FileProxy_ReadVersionCHeader+0x5d>
cmpb   $0x0,(%rbx)
jne    11d4 <FileProxy_ReadVersionCHeader+0x64>
lea    0xe2c(%rip),%rbx
lea    0xe2d(%rip),%rsi
mov    %rsp,%r12
mov    %r12,%rdi
mov    %rbx,%rdx
call   1090 <sprintf@plt>
lea    0x70(%rsp),%r13
mov    %r15,%rdi
mov    %r13,%rsi
mov    $0x400,%edx
call   1060 <FileProxy_ReadFile@plt>
mov    %r13,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%ebp
mov    %r13,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %r12,%rcx
call   1030 <Utils_StrFind@plt>
lea    0x1(%rax),%esi
mov    %r13,%rdi
mov    %ebp,%edx
mov    $0x22,%ecx
call   1080 <Utils_StrChr@plt>
mov    %eax,%ebx
lea    0x1(%rbx),%esi
mov    %r13,%rdi
mov    %ebp,%edx
mov    $0x22,%ecx
call   1080 <Utils_StrChr@plt>
movslq %ebx,%rcx
lea    (%rsp,%rcx,1),%rsi
add    $0x70,%rsi
not    %ecx
add    %eax,%ecx
movslq %ecx,%rdx
mov    %r14,%rdi
call   1070 <memcpy@plt>
xor    %eax,%eax
add    $0x478,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"VERSION\00"
@.str.1 = [12 x i8] c"#define %s\00"
define i32 @FileProxy_ReadVersionCHeader(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [1024 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [100 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%12 = bitcast [1024 x i8]* %7 to i8*
%13 = bitcast [100 x i8]* %11 to i8*
%14 = load i8*, i8** %6
%15 = icmp eq i8* %14, null
br i1 %15, label %21, label %16
16: ; preds = %3
%17 = load i8*, i8** %6
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %16, %3
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %6
br label %22
22: ; preds = %21, %16
%23 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%24 = load i8*, i8** %6
%25 = call i32 @sprintf(i8* %23, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %24)
%26 = load i8*, i8** %4
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%28 = call i32 @FileProxy_ReadFile(i8* %26, i8* %27, i32 1024)
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%30 = call i32 @strlen(i8* %29)
%31 = add nsw i32 %30, 1
store i32 %31, i32* %10
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%33 = load i32, i32* %10
%34 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%35 = call i32 @Utils_StrFind(i8* %32, i32 1, i32 %33, i8* %34)
store i32 %35, i32* %8
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%37 = load i32, i32* %8
%38 = add nsw i32 %37, 1
%39 = load i32, i32* %10
%40 = call i32 @Utils_StrChr(i8* %36, i32 %38, i32 %39, i8 signext 34)
store i32 %40, i32* %8
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%42 = load i32, i32* %8
%43 = add nsw i32 %42, 1
%44 = load i32, i32* %10
%45 = call i32 @Utils_StrChr(i8* %41, i32 %43, i32 %44, i8 signext 34)
store i32 %45, i32* %9
%46 = load i8*, i8** %5
%47 = load i32, i32* %8
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 %48
%50 = load i32, i32* %9
%51 = load i32, i32* %8
%52 = sub nsw i32 %50, %51
%53 = sub nsw i32 %52, 1
%54 = sext i32 %53 to i64
%55 = call i32 @memcpy(i8* %46, i8* %49, i64 %54)
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"VERSION\00"
@.str.1 = [12 x i8] c"#define %s\00"
define i32 @FileProxy_ReadVersionCHeader(i8* %0, i8* %1, i8* %2) {
%4 = alloca [1024 x i8]
%5 = alloca [100 x i8]
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%8 = icmp eq i8* %2, null
br i1 %8, label %12, label %9
9: ; preds = %3
%10 = load i8, i8* %2
%11 = icmp eq i8 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %9, %3
br label %13
13: ; preds = %12, %9
%14 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), %12 ], [ %2, %9 ]
%15 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = call i32 @FileProxy_ReadFile(i8* %0, i8* %6, i32 1024)
%17 = call i32 @strlen(i8* %6)
%18 = add nsw i32 %17, 1
%19 = call i32 @Utils_StrFind(i8* %6, i32 1, i32 %18, i8* %7)
%20 = add nsw i32 %19, 1
%21 = call i32 @Utils_StrChr(i8* %6, i32 %20, i32 %18, i8 signext 34)
%22 = add nsw i32 %21, 1
%23 = call i32 @Utils_StrChr(i8* %6, i32 %22, i32 %18, i8 signext 34)
%24 = sext i32 %21 to i64
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %24
%26 = xor i32 %21, -1
%27 = add i32 %23, %26
%28 = sext i32 %27 to i64
%29 = call i32 @memcpy(i8* %1, i8* %25, i64 %28)
ret i32 0
}