#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 ssize_t;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int BUFSIZ;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char const *, char *);
int read(int, char *, int);
void print_attribute(const char *path, const char *attr_name) {
  int fd = open(path, O_RDONLY);
  if (fd >= 0) {
    char buf[BUFSIZ];
    ssize_t sz = read(fd, buf, sizeof(buf) - 1);
    if (sz >= 0) {
      if (sz && buf[sz - 1] == '\n')
        sz--;
      buf[sz] = '\0';
      for (char *c = buf; *c; c++)
        if (*c == '\n')
          *c = ' ';
      printf("%s=%s\n", attr_name, buf);
    } else {
      perror("read");
    }
    close(fd);
  } else {
    perror("open");
  }
}


x86 assembly (clang, -O0):
<print_attribute>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e7d(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     1276 <print_attribute+0x126>
mov    0x2e52(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,-0x40(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
sub    $0x1,%rax
mov    %eax,%edx
call   1050 <read@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jl     1256 <print_attribute+0x106>
cmpl   $0x0,-0x2c(%rbp)
je     11f3 <print_attribute+0xa3>
mov    -0x40(%rbp),%rax
mov    -0x2c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    11f3 <print_attribute+0xa3>
mov    -0x2c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x40(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmpb   $0x0,(%rax)
je     123d <print_attribute+0xed>
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    1227 <print_attribute+0xd7>
mov    -0x38(%rbp),%rax
movb   $0x20,(%rax)
jmp    122c <print_attribute+0xdc>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    1203 <print_attribute+0xb3>
mov    -0x40(%rbp),%rdx
mov    -0x10(%rbp),%rsi
lea    0xdb4(%rip),%rdi
call   1030 <printf@plt>
jmp    1262 <print_attribute+0x112>
lea    0xdaa(%rip),%rdi
call   1070 <perror@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
jmp    1282 <print_attribute+0x132>
lea    0xd8f(%rip),%rdi
call   1070 <perror@plt>
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_attribute>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    0x2e83(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
test   %eax,%eax
js     120d <print_attribute+0xbd>
mov    %eax,%r15d
mov    %rsp,%r12
mov    0x2e57(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%rbx
mov    %rbx,%rsp
lea    -0x1(%rax),%edx
mov    %r15d,%edi
mov    %rbx,%rsi
call   1050 <read@plt>
test   %eax,%eax
js     1225 <print_attribute+0xd5>
je     11b7 <print_attribute+0x67>
lea    -0x1(%rax),%ecx
cmpb   $0xa,(%rbx,%rcx,1)
cmove  %ecx,%eax
jmp    11b9 <print_attribute+0x69>
xor    %eax,%eax
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rax
jmp    11d7 <print_attribute+0x87>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movb   $0x20,(%rax)
add    $0x1,%rax
movzbl (%rax),%ecx
cmp    $0xa,%cl
je     11d0 <print_attribute+0x80>
test   %cl,%cl
jne    11d3 <print_attribute+0x83>
lea    0xe16(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1030 <printf@plt>
mov    %r15d,%edi
call   1040 <close@plt>
mov    %r12,%rsp
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdf8(%rip),%rdi
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <perror@plt>
lea    0xddb(%rip),%rdi
call   1070 <perror@plt>
jmp    11f5 <print_attribute+0xa5>

LLVM IR (-O0):
@O_RDONLY = global i32 0
@BUFSIZ = global i32 0
@.str = [7 x i8] c"%s=%s\0A\00"
@.str.1 = [5 x i8] c"read\00"
@.str.2 = [5 x i8] c"open\00"
define void @print_attribute(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%10 = load i8*, i8** %3
%11 = load i32, i32* @O_RDONLY
%12 = call i32 @open(i8* %10, i32 %11)
store i32 %12, i32* %5
%13 = load i32, i32* %5
%14 = icmp sge i32 %13, 0
br i1 %14, label %15, label %68
15: ; preds = %2
%16 = load i32, i32* @BUFSIZ
%17 = zext i32 %16 to i64
%18 = call i8* @llvm.stacksave()
store i8* %18, i8** %6
%19 = alloca i8, i64 %17
store i64 %17, i64* %7
%20 = load i32, i32* %5
%21 = sub i64 %17, 1
%22 = trunc i64 %21 to i32
%23 = call i32 @read(i32 %20, i8* %19, i32 %22)
store i32 %23, i32* %8
%24 = load i32, i32* %8
%25 = icmp sge i32 %24, 0
br i1 %25, label %26, label %62
26: ; preds = %15
%27 = load i32, i32* %8
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %40
29: ; preds = %26
%30 = load i32, i32* %8
%31 = sub nsw i32 %30, 1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %19, i64 %32
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 10
br i1 %36, label %37, label %40
37: ; preds = %29
%38 = load i32, i32* %8
%39 = add nsw i32 %38, -1
store i32 %39, i32* %8
br label %40
40: ; preds = %37, %29, %26
%41 = load i32, i32* %8
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %19, i64 %42
store i8 0, i8* %43
store i8* %19, i8** %9
br label %44
44: ; preds = %56, %40
%45 = load i8*, i8** %9
%46 = load i8, i8* %45
%47 = icmp ne i8 %46, 0
br i1 %47, label %48, label %59
48: ; preds = %44
%49 = load i8*, i8** %9
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = icmp eq i32 %51, 10
br i1 %52, label %53, label %55
53: ; preds = %48
%54 = load i8*, i8** %9
store i8 32, i8* %54
br label %55
55: ; preds = %53, %48
br label %56
56: ; preds = %55
%57 = load i8*, i8** %9
%58 = getelementptr inbounds i8, i8* %57, i32 1
store i8* %58, i8** %9
br label %44
59: ; preds = %44
%60 = load i8*, i8** %4
%61 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %60, i8* %19)
br label %64
62: ; preds = %15
%63 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %64
64: ; preds = %62, %59
%65 = load i32, i32* %5
%66 = call i32 @close(i32 %65)
%67 = load i8*, i8** %6
br label %70
68: ; preds = %2
%69 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %70
70: ; preds = %68, %64
ret void
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@BUFSIZ = global i32 0
@.str = [7 x i8] c"%s=%s\0A\00"
@.str.1 = [5 x i8] c"read\00"
@.str.2 = [5 x i8] c"open\00"
define void @print_attribute(i8* nocapture %0, i8* %1) {
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* %0, i32 %3)
%5 = icmp sgt i32 %4, -1
br i1 %5, label %6, label %39
6: ; preds = %2
%7 = load i32, i32* @BUFSIZ
%8 = zext i32 %7 to i64
%9 = tail call i8* @llvm.stacksave()
%10 = alloca i8, i64 %8
%11 = add i32 %7, -1
%12 = call i32 @read(i32 %4, i8* %10, i32 %11)
%13 = icmp sgt i32 %12, -1
br i1 %13, label %14, label %35
14: ; preds = %6
%15 = icmp eq i32 %12, 0
br i1 %15, label %24, label %16
16: ; preds = %14
%17 = add nsw i32 %12, -1
%18 = zext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %10, i64 %18
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 10
%22 = select i1 %21, i32 %17, i32 %12
%23 = zext i32 %22 to i64
br label %24
24: ; preds = %16, %14
%25 = phi i64 [ 0, %14 ], [ %23, %16 ]
%26 = getelementptr inbounds i8, i8* %10, i64 %25
store i8 0, i8* %26
br label %27
27: ; preds = %33, %24
%28 = phi i8* [ %10, %24 ], [ %34, %33 ]
%29 = load i8, i8* %28
switch i8 %29, label %33 [
i8 0, label %30
i8 10, label %32
]
30: ; preds = %27
%31 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %10)
br label %37
32: ; preds = %27
store i8 32, i8* %28
br label %33
33: ; preds = %27, %32
%34 = getelementptr inbounds i8, i8* %28, i64 1
br label %27
35: ; preds = %6
%36 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %37
37: ; preds = %35, %30
%38 = call i32 @close(i32 %4)
br label %41
39: ; preds = %2
%40 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %41
41: ; preds = %39, %37
ret void
}