#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*/ uid_t;
struct stat {
  int /*<<< orphan*/ st_mode;
};
typedef int ssize_t;

/* Variables and functions */
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ LOG_INFO;
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_RDWR;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IRWXU;
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int S_IWUSR;
int S_IXGRP;
int S_IXOTH;
int /*<<< orphan*/ getuid();
int mkdir(char *, int);
int open(char *, int, ...);
int /*<<< orphan*/ setuid(int /*<<< orphan*/);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *);
int write(int, char *, int);
int daemon_config() {
  uid_t origUid;
  struct stat statbuf;
  int confDes;
  origUid = getuid();
  setuid(0);
  if (stat("/etc/flode/", &statbuf) != 0 || S_ISDIR(statbuf.st_mode)) {
    if (mkdir("/etc/flode/", S_IRUSR | S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH |
                                 S_IXOTH) == -1) {
      syslog(LOG_ERR, "Unable to create /etc/flode/: %m");
      return -1;
    }
    syslog(LOG_INFO, "Created configuration directory /etc/flode/");
  }
  if (stat("/etc/flode/flode.conf", &statbuf) != 0) {
    ssize_t writeLength;
    confDes = open("/etc/flode/flode.conf", O_CREAT | O_RDWR,
                   S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
    if (confDes == -1) {
      syslog(LOG_ERR, "Unable to create /etc/flode/flode.conf: %m");
      return -1;
    }
    if ((writeLength = write(confDes, "//floded configuration file", 27)) ==
        -1) {
      syslog(LOG_ERR, "Unable to write to /etc/flode/flode.conf: %m");
      return -1;
    }
    syslog(LOG_INFO, "Created configuration file /etc/flode/flode.conf");
  } else {
    confDes = open("/etc/flode/flode.conf", O_RDONLY);
    if (confDes == -1)
      syslog(LOG_ERR, "Unable to open /etc/flode/flode.conf: %m");
  }
  setuid(origUid);
  return 0;
}


x86 assembly (clang, -O0):
<daemon_config>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1050 <getuid@plt>
mov    %eax,-0x8(%rbp)
xor    %edi,%edi
call   10a0 <setuid@plt>
lea    0xea1(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1070 <stat@plt>
cmp    $0x0,%rax
jne    11c5 <daemon_config+0x45>
mov    -0x10(%rbp),%edi
call   1060 <S_ISDIR@plt>
cmp    $0x0,%rax
je     1246 <daemon_config+0xc6>
mov    0x2dcc(%rip),%rax
mov    (%rax),%esi
mov    0x2e0b(%rip),%rax
or     (%rax),%esi
mov    0x2dca(%rip),%rax
or     (%rax),%esi
mov    0x2dd1(%rip),%rax
or     (%rax),%esi
mov    0x2db0(%rip),%rax
or     (%rax),%esi
mov    0x2dd7(%rip),%rax
or     (%rax),%esi
lea    0xe3f(%rip),%rdi
call   1030 <mkdir@plt>
cmp    $0xffffffff,%eax
jne    1231 <daemon_config+0xb1>
mov    0x2d69(%rip),%rax
mov    (%rax),%edi
lea    0xde0(%rip),%rsi
call   1080 <syslog@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    137a <daemon_config+0x1fa>
mov    0x2d58(%rip),%rax
mov    (%rax),%edi
lea    0xde0(%rip),%rsi
call   1080 <syslog@plt>
lea    0xe8f(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1070 <stat@plt>
cmp    $0x0,%rax
je     132d <daemon_config+0x1ad>
mov    0x2d91(%rip),%rax
mov    (%rax),%esi
mov    0x2d68(%rip),%rax
or     (%rax),%esi
mov    0x2d1f(%rip),%rax
mov    (%rax),%edx
mov    0x2d3e(%rip),%rax
or     (%rax),%edx
mov    0x2d1d(%rip),%rax
or     (%rax),%edx
mov    0x2d0c(%rip),%rax
or     (%rax),%edx
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1090 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    12d2 <daemon_config+0x152>
mov    0x2cc8(%rip),%rax
mov    (%rax),%edi
lea    0xd8c(%rip),%rsi
call   1080 <syslog@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    137a <daemon_config+0x1fa>
mov    -0x14(%rbp),%edi
lea    0xd9c(%rip),%rsi
mov    $0x1b,%edx
call   1040 <write@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    1313 <daemon_config+0x193>
mov    0x2c87(%rip),%rax
mov    (%rax),%edi
lea    0xd92(%rip),%rsi
call   1080 <syslog@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    137a <daemon_config+0x1fa>
mov    0x2c76(%rip),%rax
mov    (%rax),%edi
lea    0xd9e(%rip),%rsi
call   1080 <syslog@plt>
jmp    136b <daemon_config+0x1eb>
mov    0x2c94(%rip),%rax
mov    (%rax),%esi
lea    0xd9f(%rip),%rdi
mov    $0x0,%al
call   1090 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1366 <daemon_config+0x1e6>
mov    0x2c28(%rip),%rax
mov    (%rax),%edi
lea    0xd91(%rip),%rsi
call   1080 <syslog@plt>
jmp    136b <daemon_config+0x1eb>
mov    -0x8(%rbp),%edi
call   10a0 <setuid@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<daemon_config>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1050 <getuid@plt>
mov    %eax,%ebx
xor    %edi,%edi
call   10a0 <setuid@plt>
lea    0xea5(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1070 <stat@plt>
test   %rax,%rax
jne    11b9 <daemon_config+0x39>
mov    0x8(%rsp),%edi
call   1060 <S_ISDIR@plt>
test   %rax,%rax
je     1219 <daemon_config+0x99>
mov    0x2dd8(%rip),%rax
mov    0x2e19(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2dd6(%rip),%rax
or     (%rax),%esi
mov    0x2ddd(%rip),%rax
or     (%rax),%esi
mov    0x2dbc(%rip),%rax
or     (%rax),%esi
mov    0x2de3(%rip),%rax
or     (%rax),%esi
lea    0xe4b(%rip),%rdi
call   1030 <mkdir@plt>
cmp    $0xffffffff,%eax
je     12a4 <daemon_config+0x124>
mov    0x2d85(%rip),%rax
mov    (%rax),%edi
lea    0xe0d(%rip),%rsi
call   1080 <syslog@plt>
lea    0xebc(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1070 <stat@plt>
test   %rax,%rax
je     12b6 <daemon_config+0x136>
mov    0x2dbe(%rip),%rax
mov    0x2d97(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2d4c(%rip),%rax
mov    0x2d6d(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2d4a(%rip),%rax
or     (%rax),%edx
mov    0x2d39(%rip),%rax
or     (%rax),%edx
lea    0xe6c(%rip),%rdi
xor    %eax,%eax
call   1090 <open@plt>
cmp    $0xffffffff,%eax
je     12f2 <daemon_config+0x172>
lea    0xdf5(%rip),%rsi
mov    %eax,%edi
mov    $0x1b,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
je     1304 <daemon_config+0x184>
lea    0xe26(%rip),%rsi
mov    0x2cee(%rip),%rax
jmp    12e0 <daemon_config+0x160>
mov    0x2cd5(%rip),%rax
mov    (%rax),%edi
lea    0xd4c(%rip),%rsi
jmp    1314 <daemon_config+0x194>
mov    0x2d0b(%rip),%rax
mov    (%rax),%esi
lea    0xe16(%rip),%rdi
xor    %eax,%eax
call   1090 <open@plt>
cmp    $0xffffffff,%eax
jne    12e7 <daemon_config+0x167>
lea    0xe19(%rip),%rsi
mov    0x2ca0(%rip),%rax
mov    (%rax),%edi
call   1080 <syslog@plt>
mov    %ebx,%edi
call   10a0 <setuid@plt>
xor    %eax,%eax
jmp    131e <daemon_config+0x19e>
mov    0x2c87(%rip),%rax
mov    (%rax),%edi
lea    0xd4b(%rip),%rsi
jmp    1314 <daemon_config+0x194>
mov    0x2c75(%rip),%rax
mov    (%rax),%edi
lea    0xd80(%rip),%rsi
call   1080 <syslog@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [12 x i8] c"/etc/flode/\00"
@S_IRUSR = global i32 0
@S_IRWXU = global i32 0
@S_IRGRP = global i32 0
@S_IXGRP = global i32 0
@S_IROTH = global i32 0
@S_IXOTH = global i32 0
@LOG_ERR = global i32 0
@.str.1 = [33 x i8] c"Unable to create /etc/flode/: %m\00"
@LOG_INFO = global i32 0
@.str.2 = [44 x i8] c"Created configuration directory /etc/flode/\00"
@.str.3 = [22 x i8] c"/etc/flode/flode.conf\00"
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@S_IWUSR = global i32 0
@.str.4 = [43 x i8] c"Unable to create /etc/flode/flode.conf: %m\00"
@.str.5 = [28 x i8] c"//floded configuration file\00"
@.str.6 = [45 x i8] c"Unable to write to /etc/flode/flode.conf: %m\00"
@.str.7 = [49 x i8] c"Created configuration file /etc/flode/flode.conf\00"
@O_RDONLY = global i32 0
@.str.8 = [41 x i8] c"Unable to open /etc/flode/flode.conf: %m\00"
define i32 @daemon_config() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.stat
%4 = alloca i32
%5 = alloca i32
%6 = call i32 (...) @getuid()
store i32 %6, i32* %2
%7 = call i32 @setuid(i32 0)
%8 = call i64 @stat(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), %struct.stat* %3)
%9 = icmp ne i64 %8, 0
br i1 %9, label %15, label %10
10: ; preds = %0
%11 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%12 = load i32, i32* %11
%13 = call i64 @S_ISDIR(i32 %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %35
15: ; preds = %10, %0
%16 = load i32, i32* @S_IRUSR
%17 = load i32, i32* @S_IRWXU
%18 = or i32 %16, %17
%19 = load i32, i32* @S_IRGRP
%20 = or i32 %18, %19
%21 = load i32, i32* @S_IXGRP
%22 = or i32 %20, %21
%23 = load i32, i32* @S_IROTH
%24 = or i32 %22, %23
%25 = load i32, i32* @S_IXOTH
%26 = or i32 %24, %25
%27 = call i32 @mkdir(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %26)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %32
29: ; preds = %15
%30 = load i32, i32* @LOG_ERR
%31 = call i32 @syslog(i32 %30, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %77
32: ; preds = %15
%33 = load i32, i32* @LOG_INFO
%34 = call i32 @syslog(i32 %33, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
br label %35
35: ; preds = %32, %10
%36 = call i64 @stat(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), %struct.stat* %3)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %65
38: ; preds = %35
%39 = load i32, i32* @O_CREAT
%40 = load i32, i32* @O_RDWR
%41 = or i32 %39, %40
%42 = load i32, i32* @S_IRUSR
%43 = load i32, i32* @S_IWUSR
%44 = or i32 %42, %43
%45 = load i32, i32* @S_IRGRP
%46 = or i32 %44, %45
%47 = load i32, i32* @S_IROTH
%48 = or i32 %46, %47
%49 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %41, i32 %48)
store i32 %49, i32* %4
%50 = load i32, i32* %4
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %55
52: ; preds = %38
%53 = load i32, i32* @LOG_ERR
%54 = call i32 @syslog(i32 %53, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %1
br label %77
55: ; preds = %38
%56 = load i32, i32* %4
%57 = call i32 @write(i32 %56, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i32 27)
store i32 %57, i32* %5
%58 = icmp eq i32 %57, -1
br i1 %58, label %59, label %62
59: ; preds = %55
%60 = load i32, i32* @LOG_ERR
%61 = call i32 @syslog(i32 %60, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %1
br label %77
62: ; preds = %55
%63 = load i32, i32* @LOG_INFO
%64 = call i32 @syslog(i32 %63, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.7, i64 0, i64 0))
br label %74
65: ; preds = %35
%66 = load i32, i32* @O_RDONLY
%67 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %66)
store i32 %67, i32* %4
%68 = load i32, i32* %4
%69 = icmp eq i32 %68, -1
br i1 %69, label %70, label %73
70: ; preds = %65
%71 = load i32, i32* @LOG_ERR
%72 = call i32 @syslog(i32 %71, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.8, i64 0, i64 0))
br label %73
73: ; preds = %70, %65
br label %74
74: ; preds = %73, %62
%75 = load i32, i32* %2
%76 = call i32 @setuid(i32 %75)
store i32 0, i32* %1
br label %77
77: ; preds = %74, %59, %52, %29
%78 = load i32, i32* %1
ret i32 %78
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [12 x i8] c"/etc/flode/\00"
@S_IRUSR = global i32 0
@S_IRWXU = global i32 0
@S_IRGRP = global i32 0
@S_IXGRP = global i32 0
@S_IROTH = global i32 0
@S_IXOTH = global i32 0
@LOG_ERR = global i32 0
@.str.1 = [33 x i8] c"Unable to create /etc/flode/: %m\00"
@LOG_INFO = global i32 0
@.str.2 = [44 x i8] c"Created configuration directory /etc/flode/\00"
@.str.3 = [22 x i8] c"/etc/flode/flode.conf\00"
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@S_IWUSR = global i32 0
@.str.4 = [43 x i8] c"Unable to create /etc/flode/flode.conf: %m\00"
@.str.5 = [28 x i8] c"//floded configuration file\00"
@.str.6 = [45 x i8] c"Unable to write to /etc/flode/flode.conf: %m\00"
@.str.7 = [49 x i8] c"Created configuration file /etc/flode/flode.conf\00"
@O_RDONLY = global i32 0
@.str.8 = [41 x i8] c"Unable to open /etc/flode/flode.conf: %m\00"
define i32 @daemon_config() {
%1 = alloca %struct.stat
%2 = bitcast %struct.stat* %1 to i8*
%3 = tail call i32 (...) @getuid()
%4 = tail call i32 @setuid(i32 0)
%5 = call i64 @stat(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), %struct.stat* %1)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %0
%8 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
%9 = load i32, i32* %8
%10 = call i64 @S_ISDIR(i32 %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %32, label %12
12: ; preds = %7, %0
%13 = load i32, i32* @S_IRUSR
%14 = load i32, i32* @S_IRWXU
%15 = or i32 %14, %13
%16 = load i32, i32* @S_IRGRP
%17 = or i32 %15, %16
%18 = load i32, i32* @S_IXGRP
%19 = or i32 %17, %18
%20 = load i32, i32* @S_IROTH
%21 = or i32 %19, %20
%22 = load i32, i32* @S_IXOTH
%23 = or i32 %21, %22
%24 = call i32 @mkdir(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %23)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %29
26: ; preds = %12
%27 = load i32, i32* @LOG_ERR
%28 = call i32 @syslog(i32 %27, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %68
29: ; preds = %12
%30 = load i32, i32* @LOG_INFO
%31 = call i32 @syslog(i32 %30, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
br label %32
32: ; preds = %29, %7
%33 = call i64 @stat(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), %struct.stat* %1)
%34 = icmp eq i64 %33, 0
br i1 %34, label %57, label %35
35: ; preds = %32
%36 = load i32, i32* @O_CREAT
%37 = load i32, i32* @O_RDWR
%38 = or i32 %37, %36
%39 = load i32, i32* @S_IRUSR
%40 = load i32, i32* @S_IWUSR
%41 = or i32 %40, %39
%42 = load i32, i32* @S_IRGRP
%43 = or i32 %41, %42
%44 = load i32, i32* @S_IROTH
%45 = or i32 %43, %44
%46 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %38, i32 %45)
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %51
48: ; preds = %35
%49 = load i32, i32* @LOG_ERR
%50 = call i32 @syslog(i32 %49, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0))
br label %68
51: ; preds = %35
%52 = call i32 @write(i32 %46, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i32 27)
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %61
54: ; preds = %51
%55 = load i32, i32* @LOG_ERR
%56 = call i32 @syslog(i32 %55, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.6, i64 0, i64 0))
br label %68
57: ; preds = %32
%58 = load i32, i32* @O_RDONLY
%59 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %58)
%60 = icmp eq i32 %59, -1
br i1 %60, label %61, label %66
61: ; preds = %57, %51
%62 = phi i32* [ @LOG_INFO, %51 ], [ @LOG_ERR, %57 ]
%63 = phi i8* [ getelementptr inbounds ([49 x i8], [49 x i8]* @.str.7, i64 0, i64 0), %51 ], [ getelementptr inbounds ([41 x i8], [41 x i8]* @.str.8, i64 0, i64 0), %57 ]
%64 = load i32, i32* %62
%65 = call i32 @syslog(i32 %64, i8* %63)
br label %66
66: ; preds = %61, %57
%67 = call i32 @setuid(i32 %3)
br label %68
68: ; preds = %48, %54, %66, %26
%69 = phi i32 [ -1, %26 ], [ 0, %66 ], [ -1, %54 ], [ -1, %48 ]
ret i32 %69
}