#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 */

/* Variables and functions */
int /*<<< orphan*/ F_OK;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ R_OK;
scalar_t__ access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int geteuid();
int getuid();
scalar_t__ open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  printf(" uid is %d\n", getuid());
  printf(" euid is %d\n", geteuid());
  if (access(argv[1], F_OK) < 0) {
    printf(" file is not existing \n");
    exit(1);
  }
  printf(" File exists \n");
  if (access(argv[1], R_OK) < 0)
    printf(" file cannot be read \n");
  else
    printf(" File can be read \n");
  if (open(argv[1], O_RDONLY) >= 0) {
    printf(" file is opened \n");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1030 <getuid@plt>
mov    %eax,%esi
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <geteuid@plt>
mov    %eax,%esi
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e15(%rip),%rax
mov    (%rax),%esi
call   1070 <access@plt>
cmp    $0x0,%rax
jge    11dc <main+0x7c>
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2ddf(%rip),%rax
mov    (%rax),%esi
call   1070 <access@plt>
cmp    $0x0,%rax
jge    121d <main+0xbd>
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    122b <main+0xcb>
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2dae(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
cmp    $0x0,%rax
jl     1259 <main+0xf9>
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    %rsi,%rbx
xor    %eax,%eax
call   1040 <getuid@plt>
lea    0xe7e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1060 <geteuid@plt>
lea    0xe73(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rbx),%rdi
mov    0x2e1b(%rip),%rax
mov    (%rax),%esi
call   1080 <access@plt>
test   %rax,%rax
js     1218 <main+0xa8>
lea    0xe59(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rbx),%rdi
mov    0x2e08(%rip),%rax
mov    (%rax),%esi
call   1080 <access@plt>
test   %rax,%rax
lea    0xe6a(%rip),%rax
lea    0xe3f(%rip),%rdi
cmovs  %rax,%rdi
call   1030 <puts@plt>
mov    0x8(%rbx),%rdi
mov    0x2dec(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
test   %rax,%rax
js     1214 <main+0xa4>
lea    0xe2b(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe42(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c" uid is %d\0A\00"
@.str.1 = [13 x i8] c" euid is %d\0A\00"
@F_OK = global i32 0
@.str.2 = [24 x i8] c" file is not existing \0A\00"
@.str.3 = [15 x i8] c" File exists \0A\00"
@R_OK = global i32 0
@.str.4 = [23 x i8] c" file cannot be read \0A\00"
@.str.5 = [20 x i8] c" File can be read \0A\00"
@O_RDONLY = global i32 0
@.str.6 = [18 x i8] c" file is opened \0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = call i32 (...) @getuid()
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = call i32 (...) @geteuid()
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @F_OK
%14 = call i64 @access(i8* %12, i32 %13)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = load i32, i32* @R_OK
%25 = call i64 @access(i8* %23, i32 %24)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %19
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
br label %31
29: ; preds = %19
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
br label %31
31: ; preds = %29, %27
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = load i32, i32* @O_RDONLY
%36 = call i64 @open(i8* %34, i32 %35)
%37 = icmp sge i64 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %31
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
br label %40
40: ; preds = %38, %31
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
@.str = [12 x i8] c" uid is %d\0A\00"
@.str.1 = [13 x i8] c" euid is %d\0A\00"
@F_OK = global i32 0
@R_OK = global i32 0
@O_RDONLY = global i32 0
@str = [14 x i8] c" File exists \00"
@str.7 = [19 x i8] c" File can be read \00"
@str.8 = [17 x i8] c" file is opened \00"
@str.9 = [22 x i8] c" file cannot be read \00"
@str.10 = [23 x i8] c" file is not existing \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 (...) @getuid()
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = tail call i32 (...) @geteuid()
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = load i32, i32* @F_OK
%10 = tail call i64 @access(i8* %8, i32 %9)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.10, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%17 = load i8*, i8** %7
%18 = load i32, i32* @R_OK
%19 = tail call i64 @access(i8* %17, i32 %18)
%20 = icmp slt i64 %19, 0
%21 = select i1 %20, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @str.9, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @str.7, i64 0, i64 0)
%22 = tail call i32 @puts(i8* dereferenceable(1) %21)
%23 = load i8*, i8** %7
%24 = load i32, i32* @O_RDONLY
%25 = tail call i64 @open(i8* %23, i32 %24)
%26 = icmp sgt i64 %25, -1
br i1 %26, label %27, label %29
27: ; preds = %15
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.8, i64 0, i64 0))
br label %29
29: ; preds = %27, %15
ret i32 0
}