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

/* Variables and functions */
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int stat(char const *, struct stat *);
void findFileAccessRights(const char *pathname) {
  int ret = -1;
  struct stat buff;
  ret = stat(pathname, &buff);
  if (ret == -1)
    perror("stat() error");
  else
    printf("Access right bits in octal format %o\n", buff.st_mode);
}


x86 assembly (clang, -O0):
<findFileAccessRights>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <stat@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    116e <findFileAccessRights+0x3e>
lea    0xe9c(%rip),%rdi
call   1050 <perror@plt>
jmp    117d <findFileAccessRights+0x4d>
mov    -0x10(%rbp),%esi
lea    0xe95(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findFileAccessRights>:
push   %rax
mov    %rsp,%rsi
call   1040 <stat@plt>
cmp    $0xffffffff,%eax
je     114e <findFileAccessRights+0x1e>
mov    (%rsp),%esi
lea    0xec5(%rip),%rdi
pop    %rax
jmp    1030 <printf@plt>
lea    0xeab(%rip),%rdi
pop    %rax
jmp    1050 <perror@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [13 x i8] c"stat() error\00"
@.str.1 = [38 x i8] c"Access right bits in octal format %o\0A\00"
define void @findFileAccessRights(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca %struct.stat
store i8* %0, i8** %2
store i32 -1, i32* %3
%5 = load i8*, i8** %2
%6 = call i32 @stat(i8* %5, %struct.stat* %4)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %15
11: ; preds = %1
%12 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%13 = load i32, i32* %12
%14 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %13)
br label %15
15: ; preds = %11, %9
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [13 x i8] c"stat() error\00"
@.str.1 = [38 x i8] c"Access right bits in octal format %o\0A\00"
define void @findFileAccessRights(i8* nocapture %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = call i32 @stat(i8* %0, %struct.stat* %2)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %12
8: ; preds = %1
%9 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%10 = load i32, i32* %9
%11 = tail call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %10)
br label %12
12: ; preds = %8, %6
ret void
}