#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 */
char *calculate_size(char *, int /*<<< orphan*/);
char *parse_proc(char *, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
char *get_user_ps_read(int pid) {
  char path[1024];
  snprintf(path, 1024, "/proc/%d/io", pid);
  char *rbytes = parse_proc(path, "read_bytes: ");
  if (rbytes == NULL)
    return NULL;
  char *read_conv = calculate_size(rbytes, 0);
  return read_conv;
}


x86 assembly (clang, -O0):
<get_user_ps_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0xc(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0xc(%rbp),%ecx
mov    $0x400,%esi
lea    0xeac(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x410(%rbp),%rdi
lea    0xea5(%rip),%rsi
call   1050 <parse_proc@plt>
mov    %rax,-0x418(%rbp)
cmpq   $0x0,-0x418(%rbp)
jne    118e <get_user_ps_read+0x5e>
movq   $0x0,-0x8(%rbp)
jmp    11ae <get_user_ps_read+0x7e>
mov    -0x418(%rbp),%rdi
xor    %esi,%esi
call   1030 <calculate_size@plt>
mov    %rax,-0x420(%rbp)
mov    -0x420(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_user_ps_read>:
push   %rbx
sub    $0x400,%rsp
mov    %edi,%ecx
lea    0xebf(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
call   1040 <snprintf@plt>
lea    0xeb4(%rip),%rsi
mov    %rbx,%rdi
call   1050 <parse_proc@plt>
test   %rax,%rax
je     1171 <get_user_ps_read+0x41>
mov    %rax,%rdi
xor    %esi,%esi
call   1030 <calculate_size@plt>
jmp    1173 <get_user_ps_read+0x43>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [12 x i8] c"/proc/%d/io\00"
@.str.1 = [13 x i8] c"read_bytes: \00"
define i8* @get_user_ps_read(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [1024 x i8]
%5 = alloca i8*
%6 = alloca i8*
store i32 %0, i32* %3
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%8 = load i32, i32* %3
%9 = call i32 @snprintf(i8* %7, i32 1024, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%11 = call i8* @parse_proc(i8* %10, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
store i8* %11, i8** %5
%12 = load i8*, i8** %5
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %15
14: ; preds = %1
store i8* null, i8** %2
br label %19
15: ; preds = %1
%16 = load i8*, i8** %5
%17 = call i8* @calculate_size(i8* %16, i32 0)
store i8* %17, i8** %6
%18 = load i8*, i8** %6
store i8* %18, i8** %2
br label %19
19: ; preds = %15, %14
%20 = load i8*, i8** %2
ret i8* %20
}

LLVM IR (-O2):
@.str = [12 x i8] c"/proc/%d/io\00"
@.str.1 = [13 x i8] c"read_bytes: \00"
define i8* @get_user_ps_read(i32 %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = call i32 @snprintf(i8* %3, i32 1024, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %0)
%5 = call i8* @parse_proc(i8* %3, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %9, label %7
7: ; preds = %1
%8 = call i8* @calculate_size(i8* %5, i32 0)
br label %9
9: ; preds = %1, %7
%10 = phi i8* [ %8, %7 ], [ null, %1 ]
ret i8* %10
}