#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 */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
scalar_t__ snprintf(char *, int, char *, int);
void openProcessFiles(int pid, int *fdStatProc, int *fdStatm) {
  char file[256] = "";
  if (snprintf(file, 256 - 1, "/proc/%d/stat", pid) < 0) {
    perror("snprintf failed");
    exit(-1);
  }
  if ((*fdStatProc = open(file, O_RDONLY)) == -1) {
    perror("open failed");
    exit(-1);
  }
  if (snprintf(file, 256 - 1, "/proc/%d/statm", pid) < 0) {
    perror("snprintf failed");
    exit(-1);
  }
  if ((*fdStatm = open(file, O_RDONLY)) == -1) {
    perror("open failed");
    exit(-1);
  }
  return;
}


x86 assembly (clang, -O0):
<openProcessFiles>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1040 <memset@plt>
lea    -0x120(%rbp),%rdi
mov    -0x4(%rbp),%ecx
mov    $0xff,%esi
lea    0xe71(%rip),%rdx
call   1030 <snprintf@plt>
cmp    $0x0,%rax
jge    11b4 <openProcessFiles+0x64>
lea    0xe69(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
lea    -0x120(%rbp),%rdi
mov    0x2e26(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    -0x10(%rbp),%rcx
mov    %eax,(%rcx)
cmp    $0xffffffff,%eax
jne    11ee <openProcessFiles+0x9e>
lea    0xe3f(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
lea    -0x120(%rbp),%rdi
mov    -0x4(%rbp),%ecx
mov    $0xff,%esi
lea    0xe26(%rip),%rdx
call   1030 <snprintf@plt>
cmp    $0x0,%rax
jge    1229 <openProcessFiles+0xd9>
lea    0xdf4(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
lea    -0x120(%rbp),%rdi
mov    0x2db1(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    -0x18(%rbp),%rcx
mov    %eax,(%rcx)
cmp    $0xffffffff,%eax
jne    1263 <openProcessFiles+0x113>
lea    0xdca(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<openProcessFiles>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%ebp
xorps  %xmm0,%xmm0
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
lea    0xe3a(%rip),%rdx
mov    %rsp,%rdi
mov    $0xff,%esi
mov    %ebp,%ecx
call   1030 <snprintf@plt>
test   %rax,%rax
js     122f <openProcessFiles+0xef>
mov    0x2e07(%rip),%r15
mov    (%r15),%esi
mov    %rsp,%rdi
call   1040 <open@plt>
mov    %eax,(%rbx)
cmp    $0xffffffff,%eax
je     1238 <openProcessFiles+0xf8>
lea    0xe30(%rip),%rdx
mov    %rsp,%rdi
mov    $0xff,%esi
mov    %ebp,%ecx
call   1030 <snprintf@plt>
test   %rax,%rax
js     122f <openProcessFiles+0xef>
mov    (%r15),%esi
mov    %rsp,%rdi
call   1040 <open@plt>
mov    %eax,(%r14)
cmp    $0xffffffff,%eax
je     1238 <openProcessFiles+0xf8>
add    $0x108,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdd8(%rip),%rdi
jmp    123f <openProcessFiles+0xff>
lea    0xddf(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/%d/stat\00"
@.str.1 = [16 x i8] c"snprintf failed\00"
@O_RDONLY = global i32 0
@.str.2 = [12 x i8] c"open failed\00"
@.str.3 = [15 x i8] c"/proc/%d/statm\00"
define void @openProcessFiles(i32 %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca [256 x i8]
store i32 %0, i32* %4
store i32* %1, i32** %5
store i32* %2, i32** %6
%8 = bitcast [256 x i8]* %7 to i8*
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%10 = load i32, i32* %4
%11 = call i64 @snprintf(i8* %9, i32 255, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %3
%14 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @exit(i32 -1)
unreachable
16: ; preds = %3
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%18 = load i32, i32* @O_RDONLY
%19 = call i32 @open(i8* %17, i32 %18)
%20 = load i32*, i32** %5
store i32 %19, i32* %20
%21 = icmp eq i32 %19, -1
br i1 %21, label %22, label %25
22: ; preds = %16
%23 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%24 = call i32 @exit(i32 -1)
unreachable
25: ; preds = %16
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%27 = load i32, i32* %4
%28 = call i64 @snprintf(i8* %26, i32 255, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %27)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %25
%31 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%32 = call i32 @exit(i32 -1)
unreachable
33: ; preds = %25
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%35 = load i32, i32* @O_RDONLY
%36 = call i32 @open(i8* %34, i32 %35)
%37 = load i32*, i32** %6
store i32 %36, i32* %37
%38 = icmp eq i32 %36, -1
br i1 %38, label %39, label %42
39: ; preds = %33
%40 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%41 = call i32 @exit(i32 -1)
unreachable
42: ; preds = %33
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/%d/stat\00"
@.str.1 = [16 x i8] c"snprintf failed\00"
@O_RDONLY = global i32 0
@.str.2 = [12 x i8] c"open failed\00"
@.str.3 = [15 x i8] c"/proc/%d/statm\00"
define void @openProcessFiles(i32 %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2) {
%4 = alloca [256 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%6 = call i64 @snprintf(i8* %5, i32 255, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %0)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %3
%9 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @exit(i32 -1)
unreachable
11: ; preds = %3
%12 = load i32, i32* @O_RDONLY
%13 = call i32 @open(i8* %5, i32 %12)
store i32 %13, i32* %1
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%17 = call i32 @exit(i32 -1)
unreachable
18: ; preds = %11
%19 = call i64 @snprintf(i8* %5, i32 255, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %0)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%23 = call i32 @exit(i32 -1)
unreachable
24: ; preds = %18
%25 = load i32, i32* @O_RDONLY
%26 = call i32 @open(i8* %5, i32 %25)
store i32 %26, i32* %2
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%30 = call i32 @exit(i32 -1)
unreachable
31: ; preds = %24
ret void
}