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

/* Variables and functions */
char EOF;
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
char getc(int /*<<< orphan*/ *);
int getegid();
int geteuid();
int getgid();
int getuid();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
int main() {
  printf("      	UID         	GID \n"
         "Real  	%d  Real  	%d \n"
         "Effective %d  Effective %d \n",
         getuid(), getgid(), geteuid(), getegid());
  FILE *fp = fopen("flag1", "r");
  if (fp == NULL) {
    printf("Error: Could not open file");
    exit(EXIT_FAILURE);
  }
  char c;
  while ((c = getc(fp)) != EOF) {
    putchar(c);
  }
  putchar('\n');
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <getuid@plt>
mov    %eax,-0x20(%rbp)
mov    $0x0,%al
call   1070 <getgid@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1060 <geteuid@plt>
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1080 <getegid@plt>
mov    -0x20(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    %eax,%r8d
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe67(%rip),%rdi
lea    0xe66(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    121c <main+0x8c>
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
jmp    1221 <main+0x91>
mov    -0x10(%rbp),%rdi
call   10b0 <getc@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%eax
mov    0x2db1(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1250 <main+0xc0>
movsbl -0x11(%rbp),%edi
call   1030 <putchar@plt>
jmp    1221 <main+0x91>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x2d6f(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
xor    %eax,%eax
call   1040 <getuid@plt>
mov    %eax,%r14d
xor    %eax,%eax
call   1070 <getgid@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1060 <geteuid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1080 <getegid@plt>
lea    0xe42(%rip),%rdi
mov    %r14d,%esi
mov    %ebp,%edx
mov    %ebx,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe76(%rip),%rdi
lea    0xe75(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     122d <main+0x9d>
mov    %rax,%rbx
mov    %rax,%rdi
call   10b0 <getc@plt>
mov    0x2def(%rip),%rbp
cmp    0x0(%rbp),%al
je     1215 <main+0x85>
xchg   %ax,%ax
movsbl %al,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   10b0 <getc@plt>
cmp    0x0(%rbp),%al
jne    1200 <main+0x70>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x2daa(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe20(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2d96(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [76 x i8] c" \09UID \09GID \0AReal \09%d Real \09%d \0AEffective %d Effective %d \0A\00"
@.str.1 = [6 x i8] c"flag1\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [27 x i8] c"Error: Could not open file\00"
@EXIT_FAILURE = global i32 0
@EOF = global i8 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i8
store i32 0, i32* %1
%4 = call i32 (...) @getuid()
%5 = call i32 (...) @getgid()
%6 = call i32 (...) @geteuid()
%7 = call i32 (...) @getegid()
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str, i64 0, i64 0), i32 %4, i32 %5, i32 %6, i32 %7)
%9 = call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %9, i32** %2
%10 = load i32*, i32** %2
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %16
12: ; preds = %0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @exit(i32 %14)
unreachable
16: ; preds = %0
br label %17
17: ; preds = %24, %16
%18 = load i32*, i32** %2
%19 = call signext i8 @getc(i32* %18)
store i8 %19, i8* %3
%20 = sext i8 %19 to i32
%21 = load i8, i8* @EOF
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %20, %22
br i1 %23, label %24, label %27
24: ; preds = %17
%25 = load i8, i8* %3
%26 = call i32 @putchar(i8 signext %25)
br label %17
27: ; preds = %17
%28 = call i32 @putchar(i8 signext 10)
%29 = load i32, i32* @EXIT_SUCCESS
ret i32 %29
}

LLVM IR (-O2):
@.str = [76 x i8] c" \09UID \09GID \0AReal \09%d Real \09%d \0AEffective %d Effective %d \0A\00"
@.str.1 = [6 x i8] c"flag1\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [27 x i8] c"Error: Could not open file\00"
@EXIT_FAILURE = global i32 0
@EOF = global i8 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = tail call i32 (...) @getuid()
%2 = tail call i32 (...) @getgid()
%3 = tail call i32 (...) @geteuid()
%4 = tail call i32 (...) @getegid()
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([76 x i8], [76 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %2, i32 %3, i32 %4)
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %12, label %8
8: ; preds = %0
%9 = tail call signext i8 @getc(i32* %6)
%10 = load i8, i8* @EOF
%11 = icmp eq i8 %9, %10
br i1 %11, label %22, label %16
12: ; preds = %0
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %8, %16
%17 = phi i8 [ %19, %16 ], [ %9, %8 ]
%18 = tail call i32 @putchar(i8 signext %17)
%19 = tail call signext i8 @getc(i32* %6)
%20 = load i8, i8* @EOF
%21 = icmp eq i8 %19, %20
br i1 %21, label %22, label %16
22: ; preds = %16, %8
%23 = tail call i32 @putchar(i8 signext 10)
%24 = load i32, i32* @EXIT_SUCCESS
ret i32 %24
}