#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 pid_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int controlla_pid(pid_t pid) {
  char dest[60];
  FILE *apri;
  sprintf(dest, "/proc/%d/maps", pid);
  apri = fopen(dest, "r");
  if (apri != NULL) {
    fclose(apri);
    return 1;
  } else
    return 0;
}


x86 assembly (clang, -O0):
<controlla_pid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x8(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xeb7(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0x50(%rbp),%rdi
lea    0xeb5(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
je     1182 <controlla_pid+0x52>
mov    -0x58(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    1189 <controlla_pid+0x59>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<controlla_pid>:
push   %rbx
sub    $0x40,%rsp
mov    %edi,%edx
lea    0xec2(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1050 <sprintf@plt>
lea    0xebe(%rip),%rsi
mov    %rbx,%rdi
call   1040 <fopen@plt>
test   %rax,%rax
je     116c <controlla_pid+0x3c>
mov    %rax,%rdi
call   1030 <fclose@plt>
mov    $0x1,%eax
jmp    116e <controlla_pid+0x3e>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/%d/maps\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @controlla_pid(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [60 x i8]
%5 = alloca i32*
store i32 %0, i32* %3
%6 = getelementptr inbounds [60 x i8], [60 x i8]* %4, i64 0, i64 0
%7 = load i32, i32* %3
%8 = call i32 @sprintf(i8* %6, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = getelementptr inbounds [60 x i8], [60 x i8]* %4, i64 0, i64 0
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %5
%11 = load i32*, i32** %5
%12 = icmp ne i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %1
%14 = load i32*, i32** %5
%15 = call i32 @fclose(i32* %14)
store i32 1, i32* %2
br label %17
16: ; preds = %1
store i32 0, i32* %2
br label %17
17: ; preds = %16, %13
%18 = load i32, i32* %2
ret i32 %18
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/%d/maps\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @controlla_pid(i32 %0) {
%2 = alloca [60 x i8]
%3 = getelementptr inbounds [60 x i8], [60 x i8]* %2, i64 0, i64 0
%4 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %0)
%5 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %9, label %7
7: ; preds = %1
%8 = tail call i32 @fclose(i32* %5)
br label %9
9: ; preds = %1, %7
%10 = phi i32 [ 1, %7 ], [ 0, %1 ]
ret i32 %10
}