#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*/ time_t;
struct tm {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ dogrep(char *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fileexist(char *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *, ...);
int /*<<< orphan*/ *strchr(char *, char);
scalar_t__ strftime(char *, int, char *, struct tm *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int config_file(char *name, char *file, int quiet) {
  char ffile[256];
  FILE *fp;
  ffile[255] = '\0';
  if (strchr(file, '%') != NULL) {
    time_t tm;
    struct tm *p;
    tm = time(NULL);
    p = localtime(&tm);
    if (strftime(ffile, 255, file, p) == 0) {
      return (-1);
    }
  } else {
    strncpy(ffile, file, 255);
  }
  if (!fileexist(ffile)) {
    if (quiet == 0) {
      printf("%s: Log file not existent: '%s'.\n", name, file);
    }
    return (-1);
  }
  if (dogrep("ossec.conf", file)) {
    printf("%s: Log file already configured: '%s'.\n", name, file);
    return (0);
  }
  fp = fopen("ossec.conf", "a");
  if (!fp) {
    printf("%s: Unable to edit configuration file.\n", name);
    return (0);
  }
  printf("%s: Adding log file to be monitored: '%s'.\n", name, file);
  fprintf(fp,
          "\r\n"
          "\r\n"
          "<!-- Extra log file -->\r\n"
          "<ossec_config>\r\n"
          "  <localfile>\r\n"
          "    <location>%s</location>\r\n"
          "    <log_format>syslog</log_format>\r\n"
          "  </localfile>\r\n"
          "</ossec_config>\r\n\r\n",
          file);
  printf("%s: Action completed.\n", name);
  fclose(fp);
  return (0);
}


x86 assembly (clang, -O0):
<config_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movb   $0x0,-0x21(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x25,%esi
call   1070 <strchr@plt>
cmp    $0x0,%rax
je     123b <config_file+0x8b>
xor    %eax,%eax
mov    %eax,%edi
call   10b0 <time@plt>
mov    %eax,-0x12c(%rbp)
lea    -0x12c(%rbp),%rdi
call   1040 <localtime@plt>
mov    %rax,-0x138(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x138(%rbp),%rcx
mov    $0xff,%esi
call   10c0 <strftime@plt>
cmp    $0x0,%rax
jne    1236 <config_file+0x86>
movl   $0xffffffff,-0x4(%rbp)
jmp    1365 <config_file+0x1b5>
jmp    1250 <config_file+0xa0>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0xff,%edx
call   1050 <strncpy@plt>
lea    -0x120(%rbp),%rdi
call   1090 <fileexist@plt>
cmp    $0x0,%eax
jne    1291 <config_file+0xe1>
cmpl   $0x0,-0x1c(%rbp)
jne    1285 <config_file+0xd5>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xd82(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1365 <config_file+0x1b5>
mov    -0x18(%rbp),%rsi
lea    0xd86(%rip),%rdi
call   1030 <dogrep@plt>
cmp    $0x0,%rax
je     12cd <config_file+0x11d>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xd73(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1365 <config_file+0x1b5>
lea    0xd4e(%rip),%rdi
lea    0xd7a(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x128(%rbp)
cmpq   $0x0,-0x128(%rbp)
jne    1313 <config_file+0x163>
mov    -0x10(%rbp),%rsi
lea    0xd57(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1365 <config_file+0x1b5>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xd5d(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x128(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xd70(%rip),%rsi
call   10a0 <fprintf@plt>
mov    -0x10(%rbp),%rsi
lea    0xe02(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x128(%rbp),%rdi
call   1060 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<config_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x118,%rsp
mov    %edx,%r15d
mov    %rsi,%rbx
mov    %rdi,%r14
movb   $0x0,0x10f(%rsp)
mov    %rsi,%rdi
mov    $0x25,%esi
call   1070 <strchr@plt>
test   %rax,%rax
je     1219 <config_file+0x69>
xor    %edi,%edi
call   10b0 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1040 <localtime@plt>
lea    0x10(%rsp),%rdi
mov    $0xff,%esi
mov    %rbx,%rdx
mov    %rax,%rcx
call   10c0 <strftime@plt>
test   %rax,%rax
jne    122b <config_file+0x7b>
mov    $0xffffffff,%ebp
jmp    12ed <config_file+0x13d>
lea    0x10(%rsp),%rdi
mov    %rbx,%rsi
mov    $0xff,%edx
call   1050 <strncpy@plt>
lea    0x10(%rsp),%rdi
call   1090 <fileexist@plt>
test   %eax,%eax
je     1258 <config_file+0xa8>
lea    0xde2(%rip),%rdi
mov    %rbx,%rsi
call   1030 <dogrep@plt>
test   %rax,%rax
je     127c <config_file+0xcc>
lea    0xdd9(%rip),%rdi
xor    %ebp,%ebp
jmp    126d <config_file+0xbd>
mov    $0xffffffff,%ebp
test   %r15d,%r15d
jne    12ed <config_file+0x13d>
lea    0xd93(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1080 <printf@plt>
jmp    12ed <config_file+0x13d>
lea    0xd9f(%rip),%rdi
lea    0xdcb(%rip),%rsi
call   10d0 <fopen@plt>
test   %rax,%rax
je     12da <config_file+0x12a>
mov    %rax,%r15
lea    0xde1(%rip),%rdi
xor    %ebp,%ebp
mov    %r14,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xdf7(%rip),%rsi
mov    %r15,%rdi
mov    %rbx,%rdx
call   10a0 <fprintf@plt>
lea    0xe87(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r15,%rdi
call   1060 <fclose@plt>
jmp    12ed <config_file+0x13d>
lea    0xd76(%rip),%rdi
xor    %ebp,%ebp
mov    %r14,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %ebp,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [34 x i8] c"%s: Log file not existent: '%s'.\0A\00"
@.str.1 = [11 x i8] c"ossec.conf\00"
@.str.2 = [40 x i8] c"%s: Log file already configured: '%s'.\0A\00"
@.str.3 = [2 x i8] c"a\00"
@.str.4 = [40 x i8] c"%s: Unable to edit configuration file.\0A\00"
@.str.5 = [44 x i8] c"%s: Adding log file to be monitored: '%s'.\0A\00"
@.str.6 = [162 x i8] c"\0D\0A\0D\0A<!-- Extra log file -->\0D\0A<ossec_config>\0D\0A <localfile>\0D\0A <location>%s</location>\0D\0A <log_format>syslog</log_format>\0D\0A </localfile>\0D\0A</ossec_config>\0D\0A\0D\0A\00"
@.str.7 = [23 x i8] c"%s: Action completed.\0A\00"
define i32 @config_file(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca [256 x i8]
%9 = alloca i32*
%10 = alloca i32
%11 = alloca %struct.tm*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 255
store i8 0, i8* %12
%13 = load i8*, i8** %6
%14 = call i32* @strchr(i8* %13, i8 signext 37)
%15 = icmp ne i32* %14, null
br i1 %15, label %16, label %26
16: ; preds = %3
%17 = call i32 @time(i32* null)
store i32 %17, i32* %10
%18 = call %struct.tm* @localtime(i32* %10)
store %struct.tm* %18, %struct.tm** %11
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%20 = load i8*, i8** %6
%21 = load %struct.tm*, %struct.tm** %11
%22 = call i64 @strftime(i8* %19, i32 255, i8* %20, %struct.tm* %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %16
store i32 -1, i32* %4
br label %68
25: ; preds = %16
br label %30
26: ; preds = %3
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%28 = load i8*, i8** %6
%29 = call i32 @strncpy(i8* %27, i8* %28, i32 255)
br label %30
30: ; preds = %26, %25
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%32 = call i32 @fileexist(i8* %31)
%33 = icmp ne i32 %32, 0
br i1 %33, label %42, label %34
34: ; preds = %30
%35 = load i32, i32* %7
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %34
%38 = load i8*, i8** %5
%39 = load i8*, i8** %6
%40 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %38, i8* %39)
br label %41
41: ; preds = %37, %34
store i32 -1, i32* %4
br label %68
42: ; preds = %30
%43 = load i8*, i8** %6
%44 = call i64 @dogrep(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %43)
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %50
46: ; preds = %42
%47 = load i8*, i8** %5
%48 = load i8*, i8** %6
%49 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* %47, i8* %48)
store i32 0, i32* %4
br label %68
50: ; preds = %42
%51 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %51, i32** %9
%52 = load i32*, i32** %9
%53 = icmp ne i32* %52, null
br i1 %53, label %57, label %54
54: ; preds = %50
%55 = load i8*, i8** %5
%56 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i8* %55)
store i32 0, i32* %4
br label %68
57: ; preds = %50
%58 = load i8*, i8** %5
%59 = load i8*, i8** %6
%60 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.5, i64 0, i64 0), i8* %58, i8* %59)
%61 = load i32*, i32** %9
%62 = load i8*, i8** %6
%63 = call i32 @fprintf(i32* %61, i8* getelementptr inbounds ([162 x i8], [162 x i8]* @.str.6, i64 0, i64 0), i8* %62)
%64 = load i8*, i8** %5
%65 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i8* %64)
%66 = load i32*, i32** %9
%67 = call i32 @fclose(i32* %66)
store i32 0, i32* %4
br label %68
68: ; preds = %57, %54, %46, %41, %24
%69 = load i32, i32* %4
ret i32 %69
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [34 x i8] c"%s: Log file not existent: '%s'.\0A\00"
@.str.1 = [11 x i8] c"ossec.conf\00"
@.str.2 = [40 x i8] c"%s: Log file already configured: '%s'.\0A\00"
@.str.3 = [2 x i8] c"a\00"
@.str.4 = [40 x i8] c"%s: Unable to edit configuration file.\0A\00"
@.str.5 = [44 x i8] c"%s: Adding log file to be monitored: '%s'.\0A\00"
@.str.6 = [162 x i8] c"\0D\0A\0D\0A<!-- Extra log file -->\0D\0A<ossec_config>\0D\0A <localfile>\0D\0A <location>%s</location>\0D\0A <log_format>syslog</log_format>\0D\0A </localfile>\0D\0A</ossec_config>\0D\0A\0D\0A\00"
@.str.7 = [23 x i8] c"%s: Action completed.\0A\00"
define i32 @config_file(i8* %0, i8* %1, i32 %2) {
%4 = alloca [256 x i8]
%5 = alloca i32
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 255
store i8 0, i8* %7
%8 = tail call i32* @strchr(i8* %1, i8 signext 37)
%9 = icmp eq i32* %8, null
br i1 %9, label %16, label %10
10: ; preds = %3
%11 = bitcast i32* %5 to i8*
%12 = tail call i32 @time(i32* null)
store i32 %12, i32* %5
%13 = call %struct.tm* @localtime(i32* %5)
%14 = call i64 @strftime(i8* %6, i32 255, i8* %1, %struct.tm* %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %40, label %18
16: ; preds = %3
%17 = call i32 @strncpy(i8* %6, i8* %1, i32 255)
br label %18
18: ; preds = %10, %16
%19 = call i32 @fileexist(i8* %6)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %18
%22 = icmp eq i32 %2, 0
br i1 %22, label %23, label %40
23: ; preds = %21
%24 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
br label %40
25: ; preds = %18
%26 = call i64 @dogrep(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%27 = icmp eq i64 %26, 0
br i1 %27, label %30, label %28
28: ; preds = %25
%29 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %1)
br label %40
30: ; preds = %25
%31 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i8* %0)
br label %40
35: ; preds = %30
%36 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.5, i64 0, i64 0), i8* %0, i8* %1)
%37 = call i32 @fprintf(i32* %31, i8* getelementptr inbounds ([162 x i8], [162 x i8]* @.str.6, i64 0, i64 0), i8* %1)
%38 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i8* %0)
%39 = call i32 @fclose(i32* %31)
br label %40
40: ; preds = %21, %23, %10, %35, %33, %28
%41 = phi i32 [ 0, %28 ], [ 0, %35 ], [ 0, %33 ], [ -1, %10 ], [ -1, %23 ], [ -1, %21 ]
ret i32 %41
}