#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*/ EXIT_FAILURE;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int geteuid();
int getuid();
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(void) {
  int fd;
  printf("process uid = [%d], euid = [%d]", getuid(), geteuid());
  if ((fd = open("/tmp/test.txt", O_RDWR)) == -1) {
    fprintf(stderr, "open failed, error: %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  printf("open success\n");
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1030 <getuid@plt>
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1050 <geteuid@plt>
mov    -0xc(%rbp),%esi
mov    %eax,%edx
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e2e(%rip),%rax
mov    (%rax),%esi
lea    0xe5d(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    120e <main+0x8e>
mov    0x2dfd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x10(%rbp),%edi
mov    %rax,%rdx
lea    0xe33(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1040 <getuid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <geteuid@plt>
lea    0xe58(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2e2e(%rip),%rax
mov    (%rax),%esi
lea    0xe5d(%rip),%rdi
call   1090 <open@plt>
cmp    $0xffffffff,%eax
je     11e6 <main+0x56>
mov    %eax,%ebx
lea    0xe70(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1070 <close@plt>
xor    %eax,%eax
pop    %rbx
ret
mov    0x2deb(%rip),%rax
mov    (%rax),%ebx
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xe2a(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1080 <fprintf@plt>
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [32 x i8] c"process uid = [%d], euid = [%d]\00"
@.str.1 = [14 x i8] c"/tmp/test.txt\00"
@O_RDWR = global i32 0
@stderr = global i32 0
@.str.2 = [24 x i8] c"open failed, error: %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.3 = [14 x i8] c"open success\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32 (...) @getuid()
%4 = call i32 (...) @geteuid()
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %3, i32 %4)
%6 = load i32, i32* @O_RDWR
%7 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %6)
store i32 %7, i32* %2
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %16
9: ; preds = %0
%10 = load i32, i32* @stderr
%11 = load i32, i32* @errno
%12 = call i8* @strerror(i32 %11)
%13 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %12)
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @exit(i32 %14)
unreachable
16: ; preds = %0
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%18 = load i32, i32* %2
%19 = call i32 @close(i32 %18)
ret i32 0
}

LLVM IR (-O2):
@.str = [32 x i8] c"process uid = [%d], euid = [%d]\00"
@.str.1 = [14 x i8] c"/tmp/test.txt\00"
@O_RDWR = global i32 0
@stderr = global i32 0
@.str.2 = [24 x i8] c"open failed, error: %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@str = [13 x i8] c"open success\00"
define i32 @main() {
%1 = tail call i32 (...) @getuid()
%2 = tail call i32 (...) @geteuid()
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %2)
%4 = load i32, i32* @O_RDWR
%5 = tail call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %14
7: ; preds = %0
%8 = load i32, i32* @stderr
%9 = load i32, i32* @errno
%10 = tail call i8* @strerror(i32 %9)
%11 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %10)
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %0
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%16 = tail call i32 @close(i32 %5)
ret i32 0
}