#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;
  scalar_t__ st_gid;
};
typedef scalar_t__ gid_t;

/* Variables and functions */
int fstatat(int, char const *, struct stat *, int);
bool expected_uid_gid(int dfd, const char *path, int flags, uid_t expected_uid,
                      gid_t expected_gid) {
  int ret;
  struct stat st;
  ret = fstatat(dfd, path, &st, flags);
  if (ret < 0)
    return false;
  return st.st_uid == expected_uid && st.st_gid == expected_gid;
}


x86 assembly (clang, -O0):
<expected_uid_gid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%ecx
lea    -0x40(%rbp),%rdx
call   1030 <fstatat@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    1156 <expected_uid_gid+0x46>
movl   $0x0,-0x4(%rbp)
jmp    1182 <expected_uid_gid+0x72>
mov    -0x40(%rbp),%rcx
xor    %eax,%eax
cmp    -0x20(%rbp),%rcx
mov    %al,-0x41(%rbp)
jne    1177 <expected_uid_gid+0x67>
mov    -0x38(%rbp),%rax
cmp    -0x28(%rbp),%rax
sete   %al
mov    %al,-0x41(%rbp)
mov    -0x41(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<expected_uid_gid>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %r8,%rbx
mov    %rcx,%r14
mov    %edx,%ecx
lea    0x8(%rsp),%rdx
call   1030 <fstatat@plt>
test   %eax,%eax
js     1141 <expected_uid_gid+0x31>
xor    0x8(%rsp),%r14
xor    0x10(%rsp),%rbx
xor    %eax,%eax
or     %r14,%rbx
sete   %al
jmp    1143 <expected_uid_gid+0x33>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.stat = type { i64, i64 }
define i32 @expected_uid_gid(i32 %0, i8* %1, i32 %2, i64 %3, i64 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i64
%11 = alloca i64
%12 = alloca i32
%13 = alloca %struct.stat
store i32 %0, i32* %7
store i8* %1, i8** %8
store i32 %2, i32* %9
store i64 %3, i64* %10
store i64 %4, i64* %11
%14 = load i32, i32* %7
%15 = load i8*, i8** %8
%16 = load i32, i32* %9
%17 = call i32 @fstatat(i32 %14, i8* %15, %struct.stat* %13, i32 %16)
store i32 %17, i32* %12
%18 = load i32, i32* %12
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %5
store i32 0, i32* %6
br label %34
21: ; preds = %5
%22 = getelementptr inbounds %struct.stat, %struct.stat* %13, i32 0, i32 0
%23 = load i64, i64* %22
%24 = load i64, i64* %10
%25 = icmp eq i64 %23, %24
br i1 %25, label %26, label %31
26: ; preds = %21
%27 = getelementptr inbounds %struct.stat, %struct.stat* %13, i32 0, i32 1
%28 = load i64, i64* %27
%29 = load i64, i64* %11
%30 = icmp eq i64 %28, %29
br label %31
31: ; preds = %26, %21
%32 = phi i1 [ false, %21 ], [ %30, %26 ]
%33 = zext i1 %32 to i32
store i32 %33, i32* %6
br label %34
34: ; preds = %31, %20
%35 = load i32, i32* %6
ret i32 %35
}

LLVM IR (-O2):
%struct.stat = type { i64, i64 }
define i32 @expected_uid_gid(i32 %0, i8* %1, i32 %2, i64 %3, i64 %4) {
%6 = alloca %struct.stat
%7 = bitcast %struct.stat* %6 to i8*
%8 = call i32 @fstatat(i32 %0, i8* %1, %struct.stat* %6, i32 %2)
%9 = icmp slt i32 %8, 0
br i1 %9, label %19, label %10
10: ; preds = %5
%11 = getelementptr inbounds %struct.stat, %struct.stat* %6, i64 0, i32 0
%12 = load i64, i64* %11
%13 = icmp eq i64 %12, %3
%14 = getelementptr inbounds %struct.stat, %struct.stat* %6, i64 0, i32 1
%15 = load i64, i64* %14
%16 = icmp eq i64 %15, %4
%17 = select i1 %13, i1 %16, i1 false
%18 = zext i1 %17 to i32
br label %19
19: ; preds = %5, %10
%20 = phi i32 [ %18, %10 ], [ 0, %5 ]
ret i32 %20
}