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

/* Variables and functions */
int PATH_MAX;
char read_text(char *, char *, size_t);
int /*<<< orphan*/ snprintf(char *, int, char *, int, char const *);
char proc_read_text(int pid, const char *item, char *buf, size_t size) {
  char path[PATH_MAX];
  snprintf(path, sizeof(path), "/proc/%d/%s", pid, item);
  return read_text(path, buf, size);
}


x86 assembly (clang, -O0):
<proc_read_text>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    0x2eb2(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x30(%rbp)
mov    %eax,%esi
mov    -0x4(%rbp),%ecx
mov    -0x10(%rbp),%r8
lea    0xe8d(%rip),%rdx
call   1030 <snprintf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <read_text@plt>
mov    -0x28(%rbp),%rcx
mov    %rcx,%rsp
movsbl %al,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<proc_read_text>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r8
mov    %edi,%ecx
mov    0x2eb4(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rbx
mov    %rsi,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xea7(%rip),%rdx
mov    %rbx,%rdi
call   1030 <snprintf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1040 <read_text@plt>
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [12 x i8] c"/proc/%d/%s\00"
define signext i8 @proc_read_text(i32 %0, i8* %1, i8* %2, i64 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i64
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i64 %3, i64* %8
%11 = load i32, i32* @PATH_MAX
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %9
%14 = alloca i8, i64 %12
store i64 %12, i64* %10
%15 = trunc i64 %12 to i32
%16 = load i32, i32* %5
%17 = load i8*, i8** %6
%18 = call i32 @snprintf(i8* %14, i32 %15, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %16, i8* %17)
%19 = load i8*, i8** %7
%20 = load i64, i64* %8
%21 = call signext i8 @read_text(i8* %14, i8* %19, i64 %20)
%22 = load i8*, i8** %9
ret i8 %21
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [12 x i8] c"/proc/%d/%s\00"
define signext i8 @proc_read_text(i32 %0, i8* %1, i8* %2, i64 %3) {
%5 = load i32, i32* @PATH_MAX
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = call i32 @snprintf(i8* %7, i32 %5, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %0, i8* %1)
%9 = call signext i8 @read_text(i8* %7, i8* %2, i64 %3)
ret i8 %9
}