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

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
char *strrchr(char *, char);
int /*<<< orphan*/ vpd_attr(char const *, char *);
void vpd_fileattr(const char *attr, const char *file, int off) {
  char line[128], *r;
  FILE *fp;
  fp = fopen(file, "r");
  if (!fp)
    return;
  fseek(fp, off, SEEK_SET);
  if (fgets(line, sizeof(line), fp) != NULL) {
    if ((r = strrchr(line, '\n')) != NULL)
      *r = 0;
    vpd_attr(attr, line);
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<vpd_fileattr>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe7f(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0xb0(%rbp)
cmpq   $0x0,-0xb0(%rbp)
jne    11a0 <vpd_fileattr+0x40>
jmp    1222 <vpd_fileattr+0xc2>
mov    -0xb0(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    0x2e2f(%rip),%rax
mov    (%rax),%edx
call   1060 <fseek@plt>
lea    -0xa0(%rbp),%rdi
mov    -0xb0(%rbp),%rdx
mov    $0x80,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1216 <vpd_fileattr+0xb6>
lea    -0xa0(%rbp),%rdi
mov    $0xa,%esi
call   1040 <strrchr@plt>
mov    %rax,-0xa8(%rbp)
cmp    $0x0,%rax
je     1206 <vpd_fileattr+0xa6>
mov    -0xa8(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
lea    -0xa0(%rbp),%rsi
call   1080 <vpd_attr@plt>
mov    -0xb0(%rbp),%rdi
call   1030 <fclose@plt>
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vpd_fileattr>:
push   %rbp
push   %r14
push   %rbx
sub    $0x80,%rsp
mov    %edx,%ebp
mov    %rsi,%rax
mov    %rdi,%r14
lea    0xe86(%rip),%rsi
mov    %rax,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     11da <vpd_fileattr+0x7a>
mov    %rax,%rbx
mov    0x2e4f(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1060 <fseek@plt>
mov    %rsp,%rdi
mov    $0x80,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11d2 <vpd_fileattr+0x72>
mov    %rsp,%rdi
mov    $0xa,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     11c7 <vpd_fileattr+0x67>
movb   $0x0,(%rax)
mov    %rsp,%rsi
mov    %r14,%rdi
call   1080 <vpd_attr@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@SEEK_SET = global i32 0
define void @vpd_fileattr(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [128 x i8]
%8 = alloca i8*
%9 = alloca i32*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%10 = load i8*, i8** %5
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %9
%12 = load i32*, i32** %9
%13 = icmp ne i32* %12, null
br i1 %13, label %15, label %14
14: ; preds = %3
br label %37
15: ; preds = %3
%16 = load i32*, i32** %9
%17 = load i32, i32* %6
%18 = load i32, i32* @SEEK_SET
%19 = call i32 @fseek(i32* %16, i32 %17, i32 %18)
%20 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%21 = load i32*, i32** %9
%22 = call i32* @fgets(i8* %20, i32 128, i32* %21)
%23 = icmp ne i32* %22, null
br i1 %23, label %24, label %34
24: ; preds = %15
%25 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%26 = call i8* @strrchr(i8* %25, i8 signext 10)
store i8* %26, i8** %8
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = load i8*, i8** %8
store i8 0, i8* %29
br label %30
30: ; preds = %28, %24
%31 = load i8*, i8** %4
%32 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%33 = call i32 @vpd_attr(i8* %31, i8* %32)
br label %34
34: ; preds = %30, %15
%35 = load i32*, i32** %9
%36 = call i32 @fclose(i32* %35)
br label %37
37: ; preds = %34, %14
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@SEEK_SET = global i32 0
define void @vpd_fileattr(i8* %0, i8* nocapture %1, i32 %2) {
%4 = alloca [128 x i8]
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%6 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %21, label %8
8: ; preds = %3
%9 = load i32, i32* @SEEK_SET
%10 = tail call i32 @fseek(i32* %6, i32 %2, i32 %9)
%11 = call i32* @fgets(i8* %5, i32 128, i32* %6)
%12 = icmp eq i32* %11, null
br i1 %12, label %19, label %13
13: ; preds = %8
%14 = call i8* @strrchr(i8* %5, i8 signext 10)
%15 = icmp eq i8* %14, null
br i1 %15, label %17, label %16
16: ; preds = %13
store i8 0, i8* %14
br label %17
17: ; preds = %16, %13
%18 = call i32 @vpd_attr(i8* %0, i8* %5)
br label %19
19: ; preds = %17, %8
%20 = call i32 @fclose(i32* %6)
br label %21
21: ; preds = %3, %19
ret void
}