#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 scalar_t__ uid_t;
struct stat {
  scalar_t__ st_uid;
};
typedef int pid_t;

/* Variables and functions */
int /*<<< orphan*/ sprintf(char *, char *, int);
scalar_t__ stat(char *, struct stat *);
bool pid_is_user(pid_t pid, uid_t uid) {
  struct stat sb;
  char buf[32];
  sprintf(buf, "/proc/%d", pid);
  if (stat(buf, &sb) != 0)
    return false;
  return (sb.st_uid == uid);
}


x86 assembly (clang, -O0):
<pid_is_user>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xec3(%rip),%rsi
call   1040 <sprintf@plt>
lea    -0x40(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <stat@plt>
cmp    $0x0,%rax
je     1165 <pid_is_user+0x45>
movl   $0x0,-0x4(%rbp)
jmp    1178 <pid_is_user+0x58>
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pid_is_user>:
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%rbx
mov    %edi,%edx
lea    0xecd(%rip),%rsi
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   1040 <sprintf@plt>
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
call   1030 <stat@plt>
xor    0x8(%rsp),%rbx
xor    %ecx,%ecx
or     %rax,%rbx
sete   %cl
mov    %ecx,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.stat = type { i64 }
@.str = [9 x i8] c"/proc/%d\00"
define i32 @pid_is_user(i32 %0, i64 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
%6 = alloca %struct.stat
%7 = alloca [32 x i8]
store i32 %0, i32* %4
store i64 %1, i64* %5
%8 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%9 = load i32, i32* %4
%10 = call i32 @sprintf(i8* %8, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%12 = call i64 @stat(i8* %11, %struct.stat* %6)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 0, i32* %3
br label %21
15: ; preds = %2
%16 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%17 = load i64, i64* %16
%18 = load i64, i64* %5
%19 = icmp eq i64 %17, %18
%20 = zext i1 %19 to i32
store i32 %20, i32* %3
br label %21
21: ; preds = %15, %14
%22 = load i32, i32* %3
ret i32 %22
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@.str = [9 x i8] c"/proc/%d\00"
define i32 @pid_is_user(i32 %0, i64 %1) {
%3 = alloca %struct.stat
%4 = alloca [32 x i8]
%5 = bitcast %struct.stat* %3 to i8*
%6 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%7 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %0)
%8 = call i64 @stat(i8* %6, %struct.stat* %3)
%9 = icmp eq i64 %8, 0
%10 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%11 = load i64, i64* %10
%12 = icmp eq i64 %11, %1
%13 = select i1 %9, i1 %12, i1 false
%14 = zext i1 %13 to i32
ret i32 %14
}