#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 /*<<< orphan*/ uid_t;
typedef int /*<<< orphan*/ mode_t;
typedef int /*<<< orphan*/ gid_t;

/* Variables and functions */
int /*<<< orphan*/ _fchmod(int, int);
int /*<<< orphan*/ _fchown(int, int /*<<< orphan*/, int);
int _mkstemp(char *);
int /*<<< orphan*/ msg(char *, int /*<<< orphan*/, int /*<<< orphan*/,
                       int /*<<< orphan*/);
char *create_file(uid_t uid, gid_t gid, mode_t mode) {
  int fd;
  static char path[] = "/tmp/testfsuidsupp.XXXXXX";
  fd = _mkstemp(path);
  _fchown(fd, 0, 101);
  _fchmod(fd, 0040);
  msg("file created %d:%d mode 0%o", uid, gid, mode);
  return path;
}


x86 assembly (clang, -O0):
<create_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
lea    0x2ef8(%rip),%rdi
call   1050 <_mkstemp@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
xor    %esi,%esi
mov    $0x65,%edx
call   1040 <_fchown@plt>
mov    -0x10(%rbp),%edi
mov    $0x20,%esi
call   1030 <_fchmod@plt>
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
lea    0xe74(%rip),%rdi
call   1060 <msg@plt>
lea    0x2eb8(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_file>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %esi,%r12d
mov    %edi,%ebx
lea    0x2ef9(%rip),%r15
mov    %r15,%rdi
call   1050 <_mkstemp@plt>
mov    %eax,%ebp
mov    %eax,%edi
xor    %esi,%esi
mov    $0x65,%edx
call   1040 <_fchown@plt>
mov    %ebp,%edi
mov    $0x20,%esi
call   1030 <_fchmod@plt>
lea    0xe7e(%rip),%rdi
mov    %ebx,%esi
mov    %r12d,%edx
mov    %r14d,%ecx
call   1060 <msg@plt>
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@create_file.path = internal global [26 x i8] c"/tmp/testfsuidsupp.XXXXXX\00"
@.str = [28 x i8] c"file created %d:%d mode 0%o\00"
define i8* @create_file(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = call i32 @_mkstemp(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @create_file.path, i64 0, i64 0))
store i32 %8, i32* %7
%9 = load i32, i32* %7
%10 = call i32 @_fchown(i32 %9, i32 0, i32 101)
%11 = load i32, i32* %7
%12 = call i32 @_fchmod(i32 %11, i32 32)
%13 = load i32, i32* %4
%14 = load i32, i32* %5
%15 = load i32, i32* %6
%16 = call i32 @msg(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %14, i32 %15)
ret i8* getelementptr inbounds ([26 x i8], [26 x i8]* @create_file.path, i64 0, i64 0)
}

LLVM IR (-O2):
@create_file.path = internal global [26 x i8] c"/tmp/testfsuidsupp.XXXXXX\00"
@.str = [28 x i8] c"file created %d:%d mode 0%o\00"
define i8* @create_file(i32 %0, i32 %1, i32 %2) {
%4 = tail call i32 @_mkstemp(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @create_file.path, i64 0, i64 0))
%5 = tail call i32 @_fchown(i32 %4, i32 0, i32 101)
%6 = tail call i32 @_fchmod(i32 %4, i32 32)
%7 = tail call i32 @msg(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %1, i32 %2)
ret i8* getelementptr inbounds ([26 x i8], [26 x i8]* @create_file.path, i64 0, i64 0)
}