#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 */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int geteuid();
int getuid();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
void task(const char *filename) {
  FILE *file;
  printf("user id = %d \n", getuid());
  printf("effective user id = %d\n", geteuid());
  file = fopen(filename, "r");
  if (NULL != file) {
    fclose(file);
  } else {
    perror("Can't open file");
  }
}


x86 assembly (clang, -O0):
<task>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1040 <getuid@plt>
mov    %eax,%esi
lea    0xe84(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1060 <geteuid@plt>
mov    %eax,%esi
lea    0xe7e(%rip),%rdi
call   1050 <printf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe86(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
je     11c4 <task+0x64>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
jmp    11d0 <task+0x70>
lea    0xe5e(%rip),%rdi
call   1080 <perror@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<task>:
push   %rbx
mov    %rdi,%rbx
xor    %eax,%eax
call   1040 <getuid@plt>
lea    0xe8e(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
xor    %eax,%eax
call   1060 <geteuid@plt>
lea    0xe88(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
lea    0xe92(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     11ab <task+0x4b>
mov    %rax,%rdi
pop    %rbx
jmp    1030 <fclose@plt>
lea    0xe77(%rip),%rdi
pop    %rbx
jmp    1080 <perror@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"user id = %d \0A\00"
@.str.1 = [24 x i8] c"effective user id = %d\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [16 x i8] c"Can't open file\00"
define void @task(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
store i8* %0, i8** %2
%4 = call i32 (...) @getuid()
%5 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = call i32 (...) @geteuid()
%7 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%8 = load i8*, i8** %2
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %9, i32** %3
%10 = load i32*, i32** %3
%11 = icmp ne i32* null, %10
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = load i32*, i32** %3
%14 = call i32 @fclose(i32* %13)
br label %17
15: ; preds = %1
%16 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
br label %17
17: ; preds = %15, %12
ret void
}

LLVM IR (-O2):
@.str = [15 x i8] c"user id = %d \0A\00"
@.str.1 = [24 x i8] c"effective user id = %d\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [16 x i8] c"Can't open file\00"
define void @task(i8* nocapture %0) {
%2 = tail call i32 (...) @getuid()
%3 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = tail call i32 (...) @geteuid()
%5 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %4)
%6 = tail call i32* @fopen(i8* %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 %10, label %8
8: ; preds = %1
%9 = tail call i32 @fclose(i32* %6)
br label %12
10: ; preds = %1
%11 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
br label %12
12: ; preds = %10, %8
ret void
}