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

/* Variables and functions */
int fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fput_proc_file(int /*<<< orphan*/ *, char const *, char const *,
                   int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char const *, char const *);
int fput_proc_vector(const char *pid, const char *name, const char *prefix,
                     const char *delim, FILE *o) {
  char filename[64];
  sprintf(filename, "/proc/%s/%s", pid, name);
  FILE *f = fopen(filename, "r");
  if (!f) {
    perror(0);
    return -1;
  }
  int r = fput_proc_file(f, prefix, delim, o);
  if (r) {
    fclose(f);
    return r;
  }
  r = fclose(f);
  if (r) {
    perror(0);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<fput_proc_vector>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
lea    -0x70(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe7e(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x70(%rbp),%rdi
lea    0xe7a(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x78(%rbp)
jne    11b9 <fput_proc_vector+0x69>
xor    %edi,%edi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    121f <fput_proc_vector+0xcf>
mov    -0x78(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
call   1030 <fput_proc_file@plt>
mov    %eax,-0x7c(%rbp)
cmpl   $0x0,-0x7c(%rbp)
je     11ef <fput_proc_vector+0x9f>
mov    -0x78(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x7c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    121f <fput_proc_vector+0xcf>
mov    -0x78(%rbp),%rdi
call   1040 <fclose@plt>
mov    %eax,-0x7c(%rbp)
cmpl   $0x0,-0x7c(%rbp)
je     1218 <fput_proc_vector+0xc8>
xor    %edi,%edi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    121f <fput_proc_vector+0xcf>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fput_proc_vector>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x40,%rsp
mov    %r8,%r14
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%rcx
mov    %rdi,%rdx
lea    0xe8e(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1070 <sprintf@plt>
lea    0xe88(%rip),%rsi
mov    %rbx,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     11b7 <fput_proc_vector+0x67>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %r14,%rcx
call   1030 <fput_proc_file@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <fclose@plt>
test   %ebp,%ebp
jne    11c3 <fput_proc_vector+0x73>
test   %eax,%eax
je     11d2 <fput_proc_vector+0x82>
xor    %edi,%edi
call   1060 <perror@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebp,%ebp
jmp    11c3 <fput_proc_vector+0x73>

LLVM IR (-O0):
@.str = [12 x i8] c"/proc/%s/%s\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @fput_proc_vector(i8* %0, i8* %1, i8* %2, i8* %3, i32* %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32*
%12 = alloca [64 x i8]
%13 = alloca i32*
%14 = alloca i32
store i8* %0, i8** %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i8* %3, i8** %10
store i32* %4, i32** %11
%15 = getelementptr inbounds [64 x i8], [64 x i8]* %12, i64 0, i64 0
%16 = load i8*, i8** %7
%17 = load i8*, i8** %8
%18 = call i32 @sprintf(i8* %15, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %16, i8* %17)
%19 = getelementptr inbounds [64 x i8], [64 x i8]* %12, i64 0, i64 0
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %13
%21 = load i32*, i32** %13
%22 = icmp ne i32* %21, null
br i1 %22, label %25, label %23
23: ; preds = %5
%24 = call i32 @perror(i32 0)
store i32 -1, i32* %6
br label %45
25: ; preds = %5
%26 = load i32*, i32** %13
%27 = load i8*, i8** %9
%28 = load i8*, i8** %10
%29 = load i32*, i32** %11
%30 = call i32 @fput_proc_file(i32* %26, i8* %27, i8* %28, i32* %29)
store i32 %30, i32* %14
%31 = load i32, i32* %14
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %25
%34 = load i32*, i32** %13
%35 = call i32 @fclose(i32* %34)
%36 = load i32, i32* %14
store i32 %36, i32* %6
br label %45
37: ; preds = %25
%38 = load i32*, i32** %13
%39 = call i32 @fclose(i32* %38)
store i32 %39, i32* %14
%40 = load i32, i32* %14
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %37
%43 = call i32 @perror(i32 0)
store i32 -1, i32* %6
br label %45
44: ; preds = %37
store i32 0, i32* %6
br label %45
45: ; preds = %44, %42, %33, %23
%46 = load i32, i32* %6
ret i32 %46
}

LLVM IR (-O2):
@.str = [12 x i8] c"/proc/%s/%s\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @fput_proc_vector(i8* %0, i8* %1, i8* %2, i8* %3, i32* %4) {
%6 = alloca [64 x i8]
%7 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%8 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%9 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %17, label %11
11: ; preds = %5
%12 = tail call i32 @fput_proc_file(i32* %9, i8* %2, i8* %3, i32* %4)
%13 = icmp eq i32 %12, 0
%14 = tail call i32 @fclose(i32* %9)
br i1 %13, label %15, label %19
15: ; preds = %11
%16 = icmp eq i32 %14, 0
br i1 %16, label %19, label %17
17: ; preds = %15, %5
%18 = tail call i32 @perror(i32 0)
br label %19
19: ; preds = %17, %11, %15
%20 = phi i32 [ 0, %15 ], [ %12, %11 ], [ -1, %17 ]
ret i32 %20
}