#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 dummy;
};

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ check(char *);
char *expand_macros(char const *);
int /*<<< orphan*/ free(char *);
scalar_t__ geteuid();
scalar_t__ getuid();
int /*<<< orphan*/ invalid_filename(char const *, int /*<<< orphan*/);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ touch_file_as_user(char *, int);
void fs_mkfile(const char *name) {
  {
    if (getuid() != 0)
      assert(geteuid() != 0);
  };
  invalid_filename(name, 0);
  char *expanded = expand_macros(name);
  check(expanded);
  struct stat s;
  if (stat(expanded, &s) == 0) {
    goto doexit;
  }
  touch_file_as_user(expanded, 0600);
doexit:
  free(expanded);
}


x86 assembly (clang, -O0):
<fs_mkfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1050 <getuid@plt>
cmp    $0x0,%rax
je     11c5 <fs_mkfile+0x35>
mov    $0x0,%al
call   1060 <geteuid@plt>
cmp    $0x0,%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1090 <invalid_filename@plt>
mov    -0x8(%rbp),%rdi
call   10b0 <expand_macros@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   10a0 <check@plt>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1080 <stat@plt>
cmp    $0x0,%rax
jne    1202 <fs_mkfile+0x72>
jmp    1210 <fs_mkfile+0x80>
mov    -0x10(%rbp),%rdi
mov    $0x180,%esi
call   1040 <touch_file_as_user@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fs_mkfile>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
xor    %eax,%eax
call   1050 <getuid@plt>
test   %rax,%rax
je     11b9 <fs_mkfile+0x29>
xor    %eax,%eax
call   1060 <geteuid@plt>
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1070 <assert@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <invalid_filename@plt>
mov    %rbx,%rdi
call   10b0 <expand_macros@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   10a0 <check@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1080 <stat@plt>
test   %rax,%rax
je     11f5 <fs_mkfile+0x65>
mov    %rbx,%rdi
mov    $0x180,%esi
call   1040 <touch_file_as_user@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
define void @fs_mkfile(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca %struct.stat
store i8* %0, i8** %2
%5 = call i64 (...) @getuid()
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %1
%8 = call i64 (...) @geteuid()
%9 = icmp ne i64 %8, 0
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
br label %12
12: ; preds = %7, %1
%13 = load i8*, i8** %2
%14 = call i32 @invalid_filename(i8* %13, i32 0)
%15 = load i8*, i8** %2
%16 = call i8* @expand_macros(i8* %15)
store i8* %16, i8** %3
%17 = load i8*, i8** %3
%18 = call i32 @check(i8* %17)
%19 = load i8*, i8** %3
%20 = call i64 @stat(i8* %19, %struct.stat* %4)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %12
br label %26
23: ; preds = %12
%24 = load i8*, i8** %3
%25 = call i32 @touch_file_as_user(i8* %24, i32 384)
br label %26
26: ; preds = %23, %22
%27 = load i8*, i8** %3
%28 = call i32 @free(i8* %27)
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
define void @fs_mkfile(i8* %0) {
%2 = alloca %struct.stat
%3 = tail call i64 (...) @getuid()
%4 = icmp eq i64 %3, 0
br i1 %4, label %10, label %5
5: ; preds = %1
%6 = tail call i64 (...) @geteuid()
%7 = icmp ne i64 %6, 0
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
br label %10
10: ; preds = %5, %1
%11 = tail call i32 @invalid_filename(i8* %0, i32 0)
%12 = tail call i8* @expand_macros(i8* %0)
%13 = tail call i32 @check(i8* %12)
%14 = bitcast %struct.stat* %2 to i8*
%15 = call i64 @stat(i8* %12, %struct.stat* %2)
%16 = icmp eq i64 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %10
%18 = call i32 @touch_file_as_user(i8* %12, i32 384)
br label %19
19: ; preds = %10, %17
%20 = call i32 @free(i8* %12)
ret void
}