#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 stat {
  int st_uid;
};

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


x86 assembly (clang, -O0):
<pid_is_user>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xec4(%rip),%rsi
call   1040 <sprintf@plt>
lea    -0x30(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1030 <stat@plt>
cmp    $0x0,%rax
je     1164 <pid_is_user+0x44>
movl   $0x0,-0x4(%rbp)
jmp    1175 <pid_is_user+0x55>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pid_is_user>:
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    %esi,%ebx
mov    %edi,%edx
lea    0xece(%rip),%rsi
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   1040 <sprintf@plt>
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
call   1030 <stat@plt>
test   %rax,%rax
sete   %al
cmp    %ebx,0x8(%rsp)
sete   %cl
and    %al,%cl
movzbl %cl,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [9 x i8] c"/proc/%d\00"
define i32 @pid_is_user(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.stat
%7 = alloca [32 x i8]
store i32 %0, i32* %4
store i32 %1, i32* %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 i32, i32* %16
%18 = load i32, i32* %5
%19 = icmp eq i32 %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 { i32 }
@.str = [9 x i8] c"/proc/%d\00"
define i32 @pid_is_user(i32 %0, i32 %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 i32, i32* %10
%12 = icmp eq i32 %11, %1
%13 = select i1 %9, i1 %12, i1 false
%14 = zext i1 %13 to i32
ret i32 %14
}