#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 {
  scalar_t__ st_uid;
  scalar_t__ st_gid;
  int st_mode;
};
struct config_entry {
  int dummy;
};

/* Variables and functions */
scalar_t__ ENOENT;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ O_RDONLY;
int S_IWGRP;
int S_IWOTH;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ err(int /*<<< orphan*/, char *);
scalar_t__ errno;
int /*<<< orphan*/ errx(int /*<<< orphan*/, char *);
scalar_t__ fstat(int, struct stat *);
int open(char *, int /*<<< orphan*/);
scalar_t__ parse_configfile(int, struct config_entry **);
struct config_entry *read_configuration(void) {
  struct stat statbuf;
  struct config_entry *entry;
  int fd = open("/etc/chpersroot.conf", O_RDONLY);
  if (fd < 0) {
    if (errno == ENOENT)
      return NULL;
    err(EXIT_FAILURE, "read_configuration");
  }
  if (fstat(fd, &statbuf))
    err(EXIT_FAILURE, "stat");
  if (0 != statbuf.st_uid || 0 != statbuf.st_gid)
    errx(EXIT_FAILURE, "config file must be owned by root");
  if (S_IWGRP & statbuf.st_mode || S_IWOTH & statbuf.st_mode)
    errx(EXIT_FAILURE, "config file must not be world writable");
  if (parse_configfile(fd, &entry))
    errx(EXIT_FAILURE, "failed to parse config file");
  close(fd);
  return entry;
}


x86 assembly (clang, -O0):
<read_configuration>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0x2e79(%rip),%rax
mov    (%rax),%esi
lea    0xe88(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    11c6 <read_configuration+0x66>
mov    0x2e3f(%rip),%rax
mov    (%rax),%rax
mov    0x2e1d(%rip),%rcx
cmp    (%rcx),%rax
jne    11b1 <read_configuration+0x51>
movq   $0x0,-0x8(%rbp)
jmp    1298 <read_configuration+0x138>
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
lea    0xe54(%rip),%rsi
call   1050 <err@plt>
mov    -0x2c(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1080 <fstat@plt>
cmp    $0x0,%rax
je     11f1 <read_configuration+0x91>
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
lea    0xe3c(%rip),%rsi
call   1050 <err@plt>
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
jne    1209 <read_configuration+0xa9>
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
je     121e <read_configuration+0xbe>
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
lea    0xe14(%rip),%rsi
call   1030 <errx@plt>
mov    0x2dbb(%rip),%rax
mov    (%rax),%eax
and    -0x10(%rbp),%eax
cmp    $0x0,%eax
jne    1248 <read_configuration+0xe8>
mov    0x2d76(%rip),%rax
mov    (%rax),%eax
and    -0x10(%rbp),%eax
cmp    $0x0,%eax
je     125d <read_configuration+0xfd>
mov    0x2d79(%rip),%rax
mov    (%rax),%edi
lea    0xdf7(%rip),%rsi
call   1030 <errx@plt>
mov    -0x2c(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   1060 <parse_configfile@plt>
cmp    $0x0,%rax
je     1288 <read_configuration+0x128>
mov    0x2d4e(%rip),%rax
mov    (%rax),%edi
lea    0xdf3(%rip),%rsi
call   1030 <errx@plt>
mov    -0x2c(%rbp),%edi
call   1040 <close@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_configuration>:
push   %rbx
sub    $0x20,%rsp
mov    0x2e7c(%rip),%rax
mov    (%rax),%esi
lea    0xe8b(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    11b2 <read_configuration+0x52>
mov    0x2e49(%rip),%rax
mov    (%rax),%rax
mov    0x2e27(%rip),%rcx
cmp    (%rcx),%rax
jne    119d <read_configuration+0x3d>
xor    %eax,%eax
jmp    1257 <read_configuration+0xf7>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
lea    0xe68(%rip),%rsi
call   1050 <err@plt>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
call   1080 <fstat@plt>
test   %rax,%rax
je     11d8 <read_configuration+0x78>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
lea    0xe55(%rip),%rsi
call   1050 <err@plt>
mov    0x8(%rsp),%rax
or     0x10(%rsp),%rax
je     11f9 <read_configuration+0x99>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
lea    0xe39(%rip),%rsi
call   1030 <errx@plt>
mov    0x2de0(%rip),%rcx
mov    0x18(%rsp),%eax
test   %eax,(%rcx)
jne    1213 <read_configuration+0xb3>
mov    0x2da1(%rip),%rcx
test   %eax,(%rcx)
je     1228 <read_configuration+0xc8>
mov    0x2dae(%rip),%rax
mov    (%rax),%edi
lea    0xe2c(%rip),%rsi
call   1030 <errx@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
call   1060 <parse_configfile@plt>
test   %rax,%rax
je     124c <read_configuration+0xec>
mov    0x2d8a(%rip),%rax
mov    (%rax),%edi
lea    0xe2f(%rip),%rsi
call   1030 <errx@plt>
mov    %ebx,%edi
call   1040 <close@plt>
mov    (%rsp),%rax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.config_entry = type { i32 }
%struct.stat = type { i64, i64, i32 }
@.str = [21 x i8] c"/etc/chpersroot.conf\00"
@O_RDONLY = global i32 0
@errno = global i64 0
@ENOENT = global i64 0
@EXIT_FAILURE = global i32 0
@.str.1 = [19 x i8] c"read_configuration\00"
@.str.2 = [5 x i8] c"stat\00"
@.str.3 = [34 x i8] c"config file must be owned by root\00"
@S_IWGRP = global i32 0
@S_IWOTH = global i32 0
@.str.4 = [39 x i8] c"config file must not be world writable\00"
@.str.5 = [28 x i8] c"failed to parse config file\00"
define %struct.config_entry* @read_configuration() {
%1 = alloca %struct.config_entry*
%2 = alloca %struct.stat
%3 = alloca %struct.config_entry*
%4 = alloca i32
%5 = load i32, i32* @O_RDONLY
%6 = call i32 @open(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %17
9: ; preds = %0
%10 = load i64, i64* @errno
%11 = load i64, i64* @ENOENT
%12 = icmp eq i64 %10, %11
br i1 %12, label %13, label %14
13: ; preds = %9
store %struct.config_entry* null, %struct.config_entry** %1
br label %61
14: ; preds = %9
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @err(i32 %15, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %14, %0
%18 = load i32, i32* %4
%19 = call i64 @fstat(i32 %18, %struct.stat* %2)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = load i32, i32* @EXIT_FAILURE
%23 = call i32 @err(i32 %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %24
24: ; preds = %21, %17
%25 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 0
%26 = load i64, i64* %25
%27 = icmp ne i64 0, %26
br i1 %27, label %32, label %28
28: ; preds = %24
%29 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 1
%30 = load i64, i64* %29
%31 = icmp ne i64 0, %30
br i1 %31, label %32, label %35
32: ; preds = %28, %24
%33 = load i32, i32* @EXIT_FAILURE
%34 = call i32 @errx(i32 %33, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
br label %35
35: ; preds = %32, %28
%36 = load i32, i32* @S_IWGRP
%37 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 2
%38 = load i32, i32* %37
%39 = and i32 %36, %38
%40 = icmp ne i32 %39, 0
br i1 %40, label %47, label %41
41: ; preds = %35
%42 = load i32, i32* @S_IWOTH
%43 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 2
%44 = load i32, i32* %43
%45 = and i32 %42, %44
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %41, %35
%48 = load i32, i32* @EXIT_FAILURE
%49 = call i32 @errx(i32 %48, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0))
br label %50
50: ; preds = %47, %41
%51 = load i32, i32* %4
%52 = call i64 @parse_configfile(i32 %51, %struct.config_entry** %3)
%53 = icmp ne i64 %52, 0
br i1 %53, label %54, label %57
54: ; preds = %50
%55 = load i32, i32* @EXIT_FAILURE
%56 = call i32 @errx(i32 %55, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
br label %57
57: ; preds = %54, %50
%58 = load i32, i32* %4
%59 = call i32 @close(i32 %58)
%60 = load %struct.config_entry*, %struct.config_entry** %3
store %struct.config_entry* %60, %struct.config_entry** %1
br label %61
61: ; preds = %57, %13
%62 = load %struct.config_entry*, %struct.config_entry** %1
ret %struct.config_entry* %62
}

LLVM IR (-O2):
%struct.config_entry = type { i32 }
%struct.stat = type { i64, i64, i32 }
@.str = [21 x i8] c"/etc/chpersroot.conf\00"
@O_RDONLY = global i32 0
@errno = global i64 0
@ENOENT = global i64 0
@EXIT_FAILURE = global i32 0
@.str.1 = [19 x i8] c"read_configuration\00"
@.str.2 = [5 x i8] c"stat\00"
@.str.3 = [34 x i8] c"config file must be owned by root\00"
@S_IWGRP = global i32 0
@S_IWOTH = global i32 0
@.str.4 = [39 x i8] c"config file must not be world writable\00"
@.str.5 = [28 x i8] c"failed to parse config file\00"
define %struct.config_entry* @read_configuration() {
%1 = alloca %struct.stat
%2 = alloca %struct.config_entry*
%3 = bitcast %struct.stat* %1 to i8*
%4 = bitcast %struct.config_entry** %2 to i8*
%5 = load i32, i32* @O_RDONLY
%6 = tail call i32 @open(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %15
8: ; preds = %0
%9 = load i64, i64* @errno
%10 = load i64, i64* @ENOENT
%11 = icmp eq i64 %9, %10
br i1 %11, label %54, label %12
12: ; preds = %8
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @err(i32 %13, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %12, %0
%16 = call i64 @fstat(i32 %6, %struct.stat* %1)
%17 = icmp eq i64 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %15
%19 = load i32, i32* @EXIT_FAILURE
%20 = tail call i32 @err(i32 %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %21
21: ; preds = %18, %15
%22 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
%23 = load i64, i64* %22
%24 = icmp ne i64 %23, 0
%25 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 1
%26 = load i64, i64* %25
%27 = icmp ne i64 %26, 0
%28 = select i1 %24, i1 true, i1 %27
br i1 %28, label %29, label %32
29: ; preds = %21
%30 = load i32, i32* @EXIT_FAILURE
%31 = tail call i32 @errx(i32 %30, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
br label %32
32: ; preds = %21, %29
%33 = load i32, i32* @S_IWGRP
%34 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 2
%35 = load i32, i32* %34
%36 = and i32 %35, %33
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %32
%39 = load i32, i32* @S_IWOTH
%40 = and i32 %39, %35
%41 = icmp eq i32 %40, 0
br i1 %41, label %45, label %42
42: ; preds = %38, %32
%43 = load i32, i32* @EXIT_FAILURE
%44 = tail call i32 @errx(i32 %43, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0))
br label %45
45: ; preds = %42, %38
%46 = call i64 @parse_configfile(i32 %6, %struct.config_entry** %2)
%47 = icmp eq i64 %46, 0
br i1 %47, label %51, label %48
48: ; preds = %45
%49 = load i32, i32* @EXIT_FAILURE
%50 = call i32 @errx(i32 %49, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
br label %51
51: ; preds = %48, %45
%52 = call i32 @close(i32 %6)
%53 = load %struct.config_entry*, %struct.config_entry** %2
br label %54
54: ; preds = %8, %51
%55 = phi %struct.config_entry* [ %53, %51 ], [ null, %8 ]
ret %struct.config_entry* %55
}