#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 */
struct ioStuff {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int _readIO(int /*<<< orphan*/ *, struct ioStuff *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, int, char *);
int readIO(int pid, struct ioStuff *s) {
  int return_code = 0;
  char buf[256];
  FILE *proc;
  snprintf(buf, 256, "/proc/%d/%s", pid, "io");
  proc = fopen(buf, "r");
  if (proc) {
    return_code = _readIO(proc, s);
    fclose(proc);
  }
  return return_code;
}


x86 assembly (clang, -O0):
<readIO>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x4(%rbp),%ecx
mov    $0x100,%esi
lea    0xe91(%rip),%rdx
lea    0xe96(%rip),%r8
call   1040 <snprintf@plt>
lea    -0x120(%rbp),%rdi
lea    0xe86(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x128(%rbp)
cmpq   $0x0,-0x128(%rbp)
je     11c2 <readIO+0x82>
mov    -0x128(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <_readIO@plt>
mov    %eax,-0x14(%rbp)
mov    -0x128(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x14(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readIO>:
push   %rbp
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    %rsi,%r14
mov    %edi,%ecx
lea    0xea9(%rip),%rdx
lea    0xeae(%rip),%r8
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
call   1040 <snprintf@plt>
lea    0xe9a(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     119c <readIO+0x5c>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1050 <_readIO@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    119e <readIO+0x5e>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.ioStuff = type { i32 }
@.str = [12 x i8] c"/proc/%d/%s\00"
@.str.1 = [3 x i8] c"io\00"
@.str.2 = [2 x i8] c"r\00"
define i32 @readIO(i32 %0, %struct.ioStuff* %1) {
%3 = alloca i32
%4 = alloca %struct.ioStuff*
%5 = alloca i32
%6 = alloca [256 x i8]
%7 = alloca i32*
store i32 %0, i32* %3
store %struct.ioStuff* %1, %struct.ioStuff** %4
store i32 0, i32* %5
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%9 = load i32, i32* %3
%10 = call i32 @snprintf(i8* %8, i32 256, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %12, i32** %7
%13 = load i32*, i32** %7
%14 = icmp ne i32* %13, null
br i1 %14, label %15, label %21
15: ; preds = %2
%16 = load i32*, i32** %7
%17 = load %struct.ioStuff*, %struct.ioStuff** %4
%18 = call i32 @_readIO(i32* %16, %struct.ioStuff* %17)
store i32 %18, i32* %5
%19 = load i32*, i32** %7
%20 = call i32 @fclose(i32* %19)
br label %21
21: ; preds = %15, %2
%22 = load i32, i32* %5
ret i32 %22
}

LLVM IR (-O2):
%struct.ioStuff = type { i32 }
@.str = [12 x i8] c"/proc/%d/%s\00"
@.str.1 = [3 x i8] c"io\00"
@.str.2 = [2 x i8] c"r\00"
define i32 @readIO(i32 %0, %struct.ioStuff* %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = call i32 @snprintf(i8* %4, i32 256, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = call i32 @_readIO(i32* %6, %struct.ioStuff* %1)
%10 = call i32 @fclose(i32* %6)
br label %11
11: ; preds = %8, %2
%12 = phi i32 [ %9, %8 ], [ 0, %2 ]
ret i32 %12
}