#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*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ perror(char *);
char *strchr(char *, char);
char *strdup(char *);
int strlen(char *);
int /*<<< orphan*/ *strstr(char *, char const *);
char *app_version_item_get(char **item_pointer, const char *item_name) {
  char line[81];
  FILE *cf = NULL;
  int len = 0;
  cf = fopen("/local/etc/sysconfig/"
             "versions.info",
             "r");
  if (cf == NULL) {
    perror("/local/etc/sysconfig/"
           "versions.info");
    return NULL;
  }
  while ((fgets(line, 81, cf)) != NULL) {
    if (strstr(line, item_name) != NULL)
      break;
  }
  fclose(cf);
  len = strlen(line);
  if (line[len - 1] == '\n')
    line[len - 1] = '\0';
  if (*item_pointer != NULL)
    free(*item_pointer);
  if (strchr(line, '=') != NULL) {
    *item_pointer = strdup(strchr(line, '=') + 1);
  } else {
    *item_pointer = strdup(line);
  }
  assert(*item_pointer != NULL);
  return *item_pointer;
}


x86 assembly (clang, -O0):
<app_version_item_get>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x78(%rbp)
movl   $0x0,-0x7c(%rbp)
lea    0xe37(%rip),%rdi
lea    0xe53(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x78(%rbp)
jne    11fd <app_version_item_get+0x5d>
lea    0xe15(%rip),%rdi
call   10a0 <perror@plt>
movq   $0x0,-0x8(%rbp)
jmp    1305 <app_version_item_get+0x165>
jmp    1202 <app_version_item_get+0x62>
lea    -0x70(%rbp),%rdi
mov    -0x78(%rbp),%rdx
mov    $0x51,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     123f <app_version_item_get+0x9f>
lea    -0x70(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10c0 <strstr@plt>
cmp    $0x0,%rax
je     123a <app_version_item_get+0x9a>
jmp    123f <app_version_item_get+0x9f>
jmp    1202 <app_version_item_get+0x62>
mov    -0x78(%rbp),%rdi
call   1040 <fclose@plt>
lea    -0x70(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x7c(%rbp)
mov    -0x7c(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x70(%rbp,%rax,1),%eax
cmp    $0xa,%eax
jne    1277 <app_version_item_get+0xd7>
mov    -0x7c(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x70(%rbp,%rax,1)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     1291 <app_version_item_get+0xf1>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
lea    -0x70(%rbp),%rdi
mov    $0x3d,%esi
call   1060 <strchr@plt>
cmp    $0x0,%rax
je     12d2 <app_version_item_get+0x132>
lea    -0x70(%rbp),%rdi
mov    $0x3d,%esi
call   1060 <strchr@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   10b0 <strdup@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
jmp    12e5 <app_version_item_get+0x145>
lea    -0x70(%rbp),%rdi
call   10b0 <strdup@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<app_version_item_get>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rsi,%r12
mov    %rdi,%r14
lea    0xe48(%rip),%rdi
lea    0xe64(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     126e <app_version_item_get+0xce>
mov    %rax,%rbx
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rdi
mov    $0x51,%esi
mov    %rbx,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1205 <app_version_item_get+0x65>
mov    %r15,%rdi
mov    %r12,%rsi
call   10c0 <strstr@plt>
test   %rax,%rax
je     11e0 <app_version_item_get+0x40>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r15,%rdi
call   1050 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%r15,1)
jne    1224 <app_version_item_get+0x84>
movb   $0x0,-0x1(%rsp,%rax,1)
mov    (%r14),%rdi
test   %rdi,%rdi
je     1231 <app_version_item_get+0x91>
call   1030 <free@plt>
mov    %r15,%rdi
mov    $0x3d,%esi
call   1060 <strchr@plt>
lea    0x1(%rax),%rdi
test   %rax,%rax
cmove  %r15,%rdi
call   10b0 <strdup@plt>
mov    %rax,(%r14)
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1080 <assert@plt>
mov    (%r14),%rax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xd8b(%rip),%rdi
call   10a0 <perror@plt>
xor    %eax,%eax
jmp    1262 <app_version_item_get+0xc2>

LLVM IR (-O0):
@.str = [35 x i8] c"/local/etc/sysconfig/versions.info\00"
@.str.1 = [2 x i8] c"r\00"
define i8* @app_version_item_get(i8** %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca [81 x i8]
%7 = alloca i32*
%8 = alloca i32
store i8** %0, i8*** %4
store i8* %1, i8** %5
store i32* null, i32** %7
store i32 0, i32* %8
%9 = call i32* @fopen(i8* getelementptr inbounds ([35 x i8], [35 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** %7
%10 = load i32*, i32** %7
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %3
br label %74
14: ; preds = %2
br label %15
15: ; preds = %26, %14
%16 = getelementptr inbounds [81 x i8], [81 x i8]* %6, i64 0, i64 0
%17 = load i32*, i32** %7
%18 = call i32* @fgets(i8* %16, i32 81, i32* %17)
%19 = icmp ne i32* %18, null
br i1 %19, label %20, label %27
20: ; preds = %15
%21 = getelementptr inbounds [81 x i8], [81 x i8]* %6, i64 0, i64 0
%22 = load i8*, i8** %5
%23 = call i32* @strstr(i8* %21, i8* %22)
%24 = icmp ne i32* %23, null
br i1 %24, label %25, label %26
25: ; preds = %20
br label %27
26: ; preds = %20
br label %15
27: ; preds = %25, %15
%28 = load i32*, i32** %7
%29 = call i32 @fclose(i32* %28)
%30 = getelementptr inbounds [81 x i8], [81 x i8]* %6, i64 0, i64 0
%31 = call i32 @strlen(i8* %30)
store i32 %31, i32* %8
%32 = load i32, i32* %8
%33 = sub nsw i32 %32, 1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [81 x i8], [81 x i8]* %6, i64 0, i64 %34
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 10
br i1 %38, label %39, label %44
39: ; preds = %27
%40 = load i32, i32* %8
%41 = sub nsw i32 %40, 1
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [81 x i8], [81 x i8]* %6, i64 0, i64 %42
store i8 0, i8* %43
br label %44
44: ; preds = %39, %27
%45 = load i8**, i8*** %4
%46 = load i8*, i8** %45
%47 = icmp ne i8* %46, null
br i1 %47, label %48, label %52
48: ; preds = %44
%49 = load i8**, i8*** %4
%50 = load i8*, i8** %49
%51 = call i32 @free(i8* %50)
br label %52
52: ; preds = %48, %44
%53 = getelementptr inbounds [81 x i8], [81 x i8]* %6, i64 0, i64 0
%54 = call i8* @strchr(i8* %53, i8 signext 61)
%55 = icmp ne i8* %54, null
br i1 %55, label %56, label %62
56: ; preds = %52
%57 = getelementptr inbounds [81 x i8], [81 x i8]* %6, i64 0, i64 0
%58 = call i8* @strchr(i8* %57, i8 signext 61)
%59 = getelementptr inbounds i8, i8* %58, i64 1
%60 = call i8* @strdup(i8* %59)
%61 = load i8**, i8*** %4
store i8* %60, i8** %61
br label %66
62: ; preds = %52
%63 = getelementptr inbounds [81 x i8], [81 x i8]* %6, i64 0, i64 0
%64 = call i8* @strdup(i8* %63)
%65 = load i8**, i8*** %4
store i8* %64, i8** %65
br label %66
66: ; preds = %62, %56
%67 = load i8**, i8*** %4
%68 = load i8*, i8** %67
%69 = icmp ne i8* %68, null
%70 = zext i1 %69 to i32
%71 = call i32 @assert(i32 %70)
%72 = load i8**, i8*** %4
%73 = load i8*, i8** %72
store i8* %73, i8** %3
br label %74
74: ; preds = %66, %12
%75 = load i8*, i8** %3
ret i8* %75
}

LLVM IR (-O2):
@.str = [35 x i8] c"/local/etc/sysconfig/versions.info\00"
@.str.1 = [2 x i8] c"r\00"
define i8* @app_version_item_get(i8** nocapture %0, i8* nocapture %1) {
%3 = alloca [81 x i8]
%4 = getelementptr inbounds [81 x i8], [81 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
br label %39
9: ; preds = %2, %12
%10 = call i32* @fgets(i8* %4, i32 81, i32* %5)
%11 = icmp eq i32* %10, null
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = call i32* @strstr(i8* %4, i8* dereferenceable(1) %1)
%14 = icmp eq i32* %13, null
br i1 %14, label %9, label %15
15: ; preds = %12, %9
%16 = call i32 @fclose(i32* %5)
%17 = call i32 @strlen(i8* %4)
%18 = add nsw i32 %17, -1
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [81 x i8], [81 x i8]* %3, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 10
br i1 %22, label %23, label %24
23: ; preds = %15
store i8 0, i8* %20
br label %24
24: ; preds = %23, %15
%25 = load i8*, i8** %0
%26 = icmp eq i8* %25, null
br i1 %26, label %29, label %27
27: ; preds = %24
%28 = call i32 @free(i8* %25)
br label %29
29: ; preds = %27, %24
%30 = call i8* @strchr(i8* %4, i8 signext 61)
%31 = icmp eq i8* %30, null
%32 = getelementptr inbounds i8, i8* %30, i64 1
%33 = select i1 %31, i8* %4, i8* %32
%34 = call i8* @strdup(i8* %33)
store i8* %34, i8** %0
%35 = icmp ne i8* %34, null
%36 = zext i1 %35 to i32
%37 = call i32 @assert(i32 %36)
%38 = load i8*, i8** %0
br label %39
39: ; preds = %29, %7
%40 = phi i8* [ null, %7 ], [ %38, %29 ]
ret i8* %40
}