#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 /*<<< orphan*/ _fstat(int, struct stat *);
int _mkstemp(char *);
int /*<<< orphan*/ _unlink(char *);
int /*<<< orphan*/ msg(char *, char *, scalar_t__, scalar_t__);
int check_fsid(char *s, uid_t uid, gid_t gid) {
  int fd;
  char path[] = "/tmp/testfsuid.XXXXXX";
  struct stat sb;
  fd = _mkstemp(path);
  _fstat(fd, &sb);
  _unlink(path);
  msg("%s: %d:%d", s, sb.st_uid, sb.st_gid);
  return (sb.st_uid == uid && sb.st_gid == gid);
}


x86 assembly (clang, -O0):
<check_fsid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0xea5(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xea2(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xea0(%rip),%eax
mov    %eax,-0x30(%rbp)
mov    0xe9a(%rip),%ax
mov    %ax,-0x2c(%rbp)
lea    -0x40(%rbp),%rdi
call   1040 <_mkstemp@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x50(%rbp),%rsi
call   1050 <_fstat@plt>
lea    -0x40(%rbp),%rdi
call   1030 <_unlink@plt>
mov    -0x8(%rbp),%rsi
mov    -0x50(%rbp),%rdx
mov    -0x48(%rbp),%rcx
lea    0xe64(%rip),%rdi
call   1060 <msg@plt>
mov    -0x50(%rbp),%rcx
xor    %eax,%eax
cmp    -0x10(%rbp),%rcx
mov    %al,-0x51(%rbp)
jne    11d8 <check_fsid+0x98>
mov    -0x48(%rbp),%rax
cmp    -0x18(%rbp),%rax
sete   %al
mov    %al,-0x51(%rbp)
mov    -0x51(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_fsid>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
movaps 0xea5(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movabs $0x5858585858582e,%rax
mov    %rax,0x1e(%rsp)
lea    0x10(%rsp),%r12
mov    %r12,%rdi
call   1040 <_mkstemp@plt>
mov    %rsp,%rsi
mov    %eax,%edi
call   1050 <_fstat@plt>
mov    %r12,%rdi
call   1030 <_unlink@plt>
mov    (%rsp),%rdx
mov    0x8(%rsp),%rcx
lea    0xe78(%rip),%rdi
mov    %r15,%rsi
call   1060 <msg@plt>
xor    (%rsp),%r14
xor    0x8(%rsp),%rbx
xor    %eax,%eax
or     %r14,%rbx
sete   %al
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.stat = type { i64, i64 }
@__const.check_fsid.path = [22 x i8] c"/tmp/testfsuid.XXXXXX\00"
@.str = [10 x i8] c"%s: %d:%d\00"
define i32 @check_fsid(i8* %0, i64 %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i32
%8 = alloca [22 x i8]
%9 = alloca %struct.stat
store i8* %0, i8** %4
store i64 %1, i64* %5
store i64 %2, i64* %6
%10 = bitcast [22 x i8]* %8 to i8*
%11 = getelementptr inbounds [22 x i8], [22 x i8]* %8, i64 0, i64 0
%12 = call i32 @_mkstemp(i8* %11)
store i32 %12, i32* %7
%13 = load i32, i32* %7
%14 = call i32 @_fstat(i32 %13, %struct.stat* %9)
%15 = getelementptr inbounds [22 x i8], [22 x i8]* %8, i64 0, i64 0
%16 = call i32 @_unlink(i8* %15)
%17 = load i8*, i8** %4
%18 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%19 = load i64, i64* %18
%20 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 1
%21 = load i64, i64* %20
%22 = call i32 @msg(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %17, i64 %19, i64 %21)
%23 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%24 = load i64, i64* %23
%25 = load i64, i64* %5
%26 = icmp eq i64 %24, %25
br i1 %26, label %27, label %32
27: ; preds = %3
%28 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 1
%29 = load i64, i64* %28
%30 = load i64, i64* %6
%31 = icmp eq i64 %29, %30
br label %32
32: ; preds = %27, %3
%33 = phi i1 [ false, %3 ], [ %31, %27 ]
%34 = zext i1 %33 to i32
ret i32 %34
}

LLVM IR (-O2):
%struct.stat = type { i64, i64 }
@__const.check_fsid.path = [22 x i8] c"/tmp/testfsuid.XXXXXX\00"
@.str = [10 x i8] c"%s: %d:%d\00"
define i32 @check_fsid(i8* %0, i64 %1, i64 %2) {
%4 = alloca [22 x i8]
%5 = alloca %struct.stat
%6 = getelementptr inbounds [22 x i8], [22 x i8]* %4, i64 0, i64 0
%7 = bitcast %struct.stat* %5 to i8*
%8 = call i32 @_mkstemp(i8* %6)
%9 = call i32 @_fstat(i32 %8, %struct.stat* %5)
%10 = call i32 @_unlink(i8* %6)
%11 = getelementptr inbounds %struct.stat, %struct.stat* %5, i64 0, i32 0
%12 = load i64, i64* %11
%13 = getelementptr inbounds %struct.stat, %struct.stat* %5, i64 0, i32 1
%14 = load i64, i64* %13
%15 = call i32 @msg(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %0, i64 %12, i64 %14)
%16 = load i64, i64* %11
%17 = icmp eq i64 %16, %1
%18 = load i64, i64* %13
%19 = icmp eq i64 %18, %2
%20 = select i1 %17, i1 %19, i1 false
%21 = zext i1 %20 to i32
ret i32 %21
}