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

/* Variables and functions */
int O_APPEND;
int O_CREAT;
int O_WRONLY;
int chmod(char const *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, char *);
int open(char const *, int, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char const *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ system(char *);
int openLogFile(const char *pathname) {
  int ret;
  int file_fd;
  char cmd[256];
  file_fd = open(pathname, O_WRONLY | O_APPEND | O_CREAT, 0640);
  if (-1 == file_fd) {
    fprintf(stderr, "open dir[%s] err %s:\n", pathname, strerror(errno));
    return -1;
  }
  ret = chmod(pathname, 0640);
  if (-1 == ret) {
    fprintf(stderr, "chmod dir[%s] err %s:\n", pathname, strerror(errno));
  }
  snprintf(cmd, sizeof(cmd), "chown %s %s", "root:system", pathname);
  system(cmd);
  return file_fd;
}


x86 assembly (clang, -O0):
<openLogFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
mov    0x2e35(%rip),%rax
or     (%rax),%esi
mov    0x2e6c(%rip),%rax
or     (%rax),%esi
mov    $0x1a0,%edx
call   1070 <open@plt>
mov    %eax,-0x18(%rbp)
mov    $0xffffffff,%eax
cmp    -0x18(%rbp),%eax
jne    11f9 <openLogFile+0x99>
mov    0x2e28(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x12c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x128(%rbp)
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x12c(%rbp),%edi
mov    -0x128(%rbp),%rdx
mov    %rax,%rcx
lea    0xe18(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1291 <openLogFile+0x131>
mov    -0x10(%rbp),%rdi
mov    $0x1a0,%esi
call   1060 <chmod@plt>
mov    %eax,-0x14(%rbp)
mov    $0xffffffff,%eax
cmp    -0x14(%rbp),%eax
jne    125c <openLogFile+0xfc>
mov    0x2db9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x13c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x138(%rbp)
mov    0x2d97(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x13c(%rbp),%edi
mov    -0x138(%rbp),%rdx
mov    %rax,%rcx
lea    0xdbf(%rip),%rsi
call   1050 <fprintf@plt>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%r8
mov    $0x100,%esi
lea    0xdba(%rip),%rdx
lea    0xdbf(%rip),%rcx
call   1040 <snprintf@plt>
lea    -0x120(%rbp),%rdi
call   1030 <system@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<openLogFile>:
push   %rbp
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    0x2e4e(%rip),%rax
mov    0x2e3f(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rdi,%rbx
mov    0x2e71(%rip),%rax
or     (%rax),%esi
mov    $0x1a0,%edx
call   1070 <open@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
je     1204 <openLogFile+0xa4>
mov    %rbx,%rdi
mov    $0x1a0,%esi
call   1060 <chmod@plt>
cmp    $0xffffffff,%eax
jne    11d9 <openLogFile+0x79>
mov    0x2e25(%rip),%rax
mov    (%rax),%r14d
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe4b(%rip),%rsi
mov    %r14d,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1050 <fprintf@plt>
lea    0xe4d(%rip),%rdx
lea    0xe52(%rip),%rcx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x100,%esi
mov    %rbx,%r8
call   1040 <snprintf@plt>
mov    %r14,%rdi
call   1030 <system@plt>
jmp    1231 <openLogFile+0xd1>
mov    0x2dcd(%rip),%rax
mov    (%rax),%r14d
mov    0x2dbb(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xddd(%rip),%rsi
mov    %r14d,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1050 <fprintf@plt>
mov    %ebp,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@O_WRONLY = global i32 0
@O_APPEND = global i32 0
@O_CREAT = global i32 0
@stderr = global i32 0
@.str = [22 x i8] c"open dir[%s] err %s:\0A\00"
@errno = global i32 0
@.str.1 = [23 x i8] c"chmod dir[%s] err %s:\0A\00"
@.str.2 = [12 x i8] c"chown %s %s\00"
@.str.3 = [12 x i8] c"root:system\00"
define i32 @openLogFile(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca [256 x i8]
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = load i32, i32* @O_WRONLY
%9 = load i32, i32* @O_APPEND
%10 = or i32 %8, %9
%11 = load i32, i32* @O_CREAT
%12 = or i32 %10, %11
%13 = call i32 @open(i8* %7, i32 %12, i32 416)
store i32 %13, i32* %5
%14 = load i32, i32* %5
%15 = icmp eq i32 -1, %14
br i1 %15, label %16, label %22
16: ; preds = %1
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %3
%19 = load i32, i32* @errno
%20 = call i8* @strerror(i32 %19)
%21 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %18, i8* %20)
store i32 -1, i32* %2
br label %40
22: ; preds = %1
%23 = load i8*, i8** %3
%24 = call i32 @chmod(i8* %23, i32 416)
store i32 %24, i32* %4
%25 = load i32, i32* %4
%26 = icmp eq i32 -1, %25
br i1 %26, label %27, label %33
27: ; preds = %22
%28 = load i32, i32* @stderr
%29 = load i8*, i8** %3
%30 = load i32, i32* @errno
%31 = call i8* @strerror(i32 %30)
%32 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %29, i8* %31)
br label %33
33: ; preds = %27, %22
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%35 = load i8*, i8** %3
%36 = call i32 @snprintf(i8* %34, i32 256, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %35)
%37 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%38 = call i32 @system(i8* %37)
%39 = load i32, i32* %5
store i32 %39, i32* %2
br label %40
40: ; preds = %33, %16
%41 = load i32, i32* %2
ret i32 %41
}

LLVM IR (-O2):
@O_WRONLY = global i32 0
@O_APPEND = global i32 0
@O_CREAT = global i32 0
@stderr = global i32 0
@.str = [22 x i8] c"open dir[%s] err %s:\0A\00"
@errno = global i32 0
@.str.1 = [23 x i8] c"chmod dir[%s] err %s:\0A\00"
@.str.2 = [12 x i8] c"chown %s %s\00"
@.str.3 = [12 x i8] c"root:system\00"
define i32 @openLogFile(i8* %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = load i32, i32* @O_WRONLY
%5 = load i32, i32* @O_APPEND
%6 = or i32 %5, %4
%7 = load i32, i32* @O_CREAT
%8 = or i32 %6, %7
%9 = tail call i32 @open(i8* %0, i32 %8, i32 416)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %16
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = load i32, i32* @errno
%14 = tail call i8* @strerror(i32 %13)
%15 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %14)
br label %27
16: ; preds = %1
%17 = tail call i32 @chmod(i8* %0, i32 416)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %24
19: ; preds = %16
%20 = load i32, i32* @stderr
%21 = load i32, i32* @errno
%22 = tail call i8* @strerror(i32 %21)
%23 = tail call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %22)
br label %24
24: ; preds = %19, %16
%25 = call i32 @snprintf(i8* %3, i32 256, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%26 = call i32 @system(i8* %3)
br label %27
27: ; preds = %24, %11
ret i32 %9
}