#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_ino;
  scalar_t__ st_size;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ atol(char *);
scalar_t__ chmod(char *, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, long, long);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ strcpy(char *, char *);
int check_log(char *logname, char *offset_filename) {
  FILE *input, *offset_output;
  struct stat file_stat;
  char inode_buffer[1024], offset_buffer[1024], buffer[1024];
  long offset_position;
  if ((input = fopen(logname, "rb")) == NULL) {
    printf("File %s cannot be read.\n", logname);
    return (2);
  }
  if ((offset_output = fopen(offset_filename, "rb")) != NULL) {
    if ((fgets(buffer, 1024, offset_output)) != NULL)
      strcpy(inode_buffer, buffer);
    if ((fgets(buffer, 1024, offset_output)) != NULL)
      strcpy(offset_buffer, buffer);
    fclose(offset_output);
  } else {
    strcpy(inode_buffer, "0");
    offset_position = 0L;
  }
  if ((stat(logname, &file_stat)) != 0) {
    printf("Cannot get %s file size.\n", logname);
    return (3);
  }
  if (((atol(inode_buffer)) == (file_stat.st_ino)) &&
      (atol(offset_buffer) > (file_stat.st_size))) {
    offset_position = 0L;
    printf("***************\n");
    printf("*** WARNING ***: Log file %s is smaller than last time checked!\n",
           logname);
    printf("***************	 This could indicate tampering.\n");
  }
  if (((atol(inode_buffer)) != (file_stat.st_ino)) ||
      (atol(offset_buffer) > (file_stat.st_size)))
    offset_position = 0L;
  else
    offset_position = atol(offset_buffer);
  fseek(input, offset_position, 0);
  while ((fgets(buffer, 1024, input)) != NULL)
    printf("%s", buffer);
  if ((offset_output = fopen(offset_filename, "w")) == NULL) {
    printf("File %s cannot be created. Check your permissions.\n",
           offset_filename);
    fclose(input);
    fclose(offset_output);
    return (4);
  } else {
    if ((chmod(offset_filename, 00600)) != 0) {
      printf("Cannot set permissions on file %s\n", offset_filename);
      return (3);
    } else {
      offset_position = ftell(input);
      fprintf(offset_output, "%ld\n%ld", (long)file_stat.st_ino,
              offset_position);
    }
  }
  fclose(input);
  fclose(offset_output);
  return (0);
}


x86 assembly (clang, -O0):
<check_log>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe32(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11ff <check_log+0x4f>
mov    -0x10(%rbp),%rsi
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    14ae <check_log+0x2fe>
mov    -0x18(%rbp),%rdi
lea    0xdf6(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     128f <check_log+0xdf>
lea    -0xc40(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x400,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     124f <check_log+0x9f>
lea    -0x440(%rbp),%rdi
lea    -0xc40(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0xc40(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x400,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1281 <check_log+0xd1>
lea    -0x840(%rbp),%rdi
lea    -0xc40(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
jmp    12ad <check_log+0xfd>
lea    -0x440(%rbp),%rdi
lea    0xd7f(%rip),%rsi
call   1030 <strcpy@plt>
movq   $0x0,-0xc48(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1090 <stat@plt>
cmp    $0x0,%rax
je     12e2 <check_log+0x132>
mov    -0x10(%rbp),%rsi
lea    0xd4f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x3,-0x4(%rbp)
jmp    14ae <check_log+0x2fe>
lea    -0x440(%rbp),%rdi
call   10c0 <atol@plt>
cmp    -0x38(%rbp),%rax
jne    1347 <check_log+0x197>
lea    -0x840(%rbp),%rdi
call   10c0 <atol@plt>
cmp    -0x30(%rbp),%rax
jle    1347 <check_log+0x197>
movq   $0x0,-0xc48(%rbp)
lea    0xd18(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xd17(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd4a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x440(%rbp),%rdi
call   10c0 <atol@plt>
cmp    -0x38(%rbp),%rax
jne    1373 <check_log+0x1c3>
lea    -0x840(%rbp),%rdi
call   10c0 <atol@plt>
cmp    -0x30(%rbp),%rax
jle    1383 <check_log+0x1d3>
movq   $0x0,-0xc48(%rbp)
jmp    1396 <check_log+0x1e6>
lea    -0x840(%rbp),%rdi
call   10c0 <atol@plt>
mov    %rax,-0xc48(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0xc48(%rbp),%rsi
xor    %edx,%edx
call   10a0 <fseek@plt>
lea    -0xc40(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x400,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     13e1 <check_log+0x231>
lea    -0xc40(%rbp),%rsi
lea    0xce6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    13a8 <check_log+0x1f8>
mov    -0x18(%rbp),%rdi
lea    0xcd2(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    142f <check_log+0x27f>
mov    -0x18(%rbp),%rsi
lea    0xcb6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x4,-0x4(%rbp)
jmp    14ae <check_log+0x2fe>
mov    -0x18(%rbp),%rdi
mov    $0x180,%esi
call   10b0 <chmod@plt>
cmp    $0x0,%rax
je     1465 <check_log+0x2b5>
mov    -0x18(%rbp),%rsi
lea    0xca2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x3,-0x4(%rbp)
jmp    14ae <check_log+0x2fe>
mov    -0x20(%rbp),%rdi
call   1080 <ftell@plt>
mov    %rax,-0xc48(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    -0xc48(%rbp),%rcx
lea    0xc8c(%rip),%rsi
call   1070 <fprintf@plt>
jmp    1495 <check_log+0x2e5>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_log>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xc10,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe23(%rip),%rsi
call   10e0 <fopen@plt>
test   %rax,%rax
je     125d <check_log+0x9d>
mov    %rax,%r12
lea    0xe0f(%rip),%rsi
mov    %r14,%rdi
call   10e0 <fopen@plt>
test   %rax,%rax
je     1275 <check_log+0xb5>
mov    %rax,%rbx
lea    0x10(%rsp),%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     122a <check_log+0x6a>
lea    0x410(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1030 <strcpy@plt>
lea    0x10(%rsp),%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1253 <check_log+0x93>
lea    0x810(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
jmp    1289 <check_log+0xc9>
lea    0xd9f(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x2,%eax
jmp    12af <check_log+0xef>
lea    0xda0(%rip),%rsi
lea    0x410(%rsp),%rdi
call   1030 <strcpy@plt>
mov    %rsp,%rsi
mov    %r15,%rdi
call   10a0 <stat@plt>
test   %rax,%rax
je     12c0 <check_log+0x100>
lea    0xd7e(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x3,%eax
add    $0xc10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0x410(%rsp),%rdi
call   10d0 <atol@plt>
mov    (%rsp),%rbx
cmp    %rbx,%rax
jne    131d <check_log+0x15d>
mov    %rax,%r13
lea    0x810(%rsp),%rdi
call   10d0 <atol@plt>
mov    %r13,%rbx
cmp    0x8(%rsp),%rax
jle    131d <check_log+0x15d>
lea    0xde6(%rip),%rdi
call   1040 <puts@plt>
lea    0xd35(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xdd9(%rip),%rdi
call   1040 <puts@plt>
mov    (%rsp),%rbx
lea    0x410(%rsp),%rdi
call   10d0 <atol@plt>
cmp    %rbx,%rax
jne    1349 <check_log+0x189>
lea    0x810(%rsp),%rdi
call   10d0 <atol@plt>
xor    %esi,%esi
cmp    0x8(%rsp),%rax
cmovle %rax,%rsi
jmp    134b <check_log+0x18b>
xor    %esi,%esi
mov    %r12,%rdi
xor    %edx,%edx
call   10b0 <fseek@plt>
lea    0x10(%rsp),%rdi
mov    $0x400,%esi
mov    %r12,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     13a2 <check_log+0x1e2>
lea    0xd06(%rip),%r15
lea    0x10(%rsp),%rbx
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r12,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
jne    1380 <check_log+0x1c0>
lea    0xcd3(%rip),%rsi
mov    %r14,%rdi
call   10e0 <fopen@plt>
test   %rax,%rax
je     13da <check_log+0x21a>
mov    %rax,%rbx
mov    %r14,%rdi
mov    $0x180,%esi
call   10c0 <chmod@plt>
test   %rax,%rax
je     1404 <check_log+0x244>
lea    0xce0(%rip),%rdi
mov    %r14,%rsi
jmp    12a3 <check_log+0xe3>
lea    0xc9d(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
xor    %edi,%edi
call   1050 <fclose@plt>
mov    $0x4,%eax
jmp    12af <check_log+0xef>
mov    %r12,%rdi
call   1090 <ftell@plt>
mov    (%rsp),%rdx
lea    0xcbe(%rip),%rsi
mov    %rbx,%rdi
mov    %rax,%rcx
call   1080 <fprintf@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
jmp    12af <check_log+0xef>

LLVM IR (-O0):
%struct.stat = type { i64, i64 }
@.str = [3 x i8] c"rb\00"
@.str.1 = [25 x i8] c"File %s cannot be read.\0A\00"
@.str.2 = [2 x i8] c"0\00"
@.str.3 = [26 x i8] c"Cannot get %s file size.\0A\00"
@.str.4 = [17 x i8] c"***************\0A\00"
@.str.5 = [65 x i8] c"*** WARNING ***: Log file %s is smaller than last time checked!\0A\00"
@.str.6 = [49 x i8] c"***************\09 This could indicate tampering.\0A\00"
@.str.7 = [3 x i8] c"%s\00"
@.str.8 = [2 x i8] c"w\00"
@.str.9 = [52 x i8] c"File %s cannot be created. Check your permissions.\0A\00"
@.str.10 = [35 x i8] c"Cannot set permissions on file %s\0A\00"
@.str.11 = [8 x i8] c"%ld\0A%ld\00"
define i32 @check_log(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca %struct.stat
%9 = alloca [1024 x i8]
%10 = alloca [1024 x i8]
%11 = alloca [1024 x i8]
%12 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
%13 = load i8*, i8** %4
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %6
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = load i8*, i8** %4
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %17)
store i32 2, i32* %3
br label %131
19: ; preds = %2
%20 = load i8*, i8** %5
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %21, i32** %7
%22 = icmp ne i32* %21, null
br i1 %22, label %23, label %44
23: ; preds = %19
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%25 = load i32*, i32** %7
%26 = call i32* @fgets(i8* %24, i32 1024, i32* %25)
%27 = icmp ne i32* %26, null
br i1 %27, label %28, label %32
28: ; preds = %23
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%31 = call i32 @strcpy(i8* %29, i8* %30)
br label %32
32: ; preds = %28, %23
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%34 = load i32*, i32** %7
%35 = call i32* @fgets(i8* %33, i32 1024, i32* %34)
%36 = icmp ne i32* %35, null
br i1 %36, label %37, label %41
37: ; preds = %32
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%40 = call i32 @strcpy(i8* %38, i8* %39)
br label %41
41: ; preds = %37, %32
%42 = load i32*, i32** %7
%43 = call i32 @fclose(i32* %42)
br label %47
44: ; preds = %19
%45 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%46 = call i32 @strcpy(i8* %45, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i64 0, i64* %12
br label %47
47: ; preds = %44, %41
%48 = load i8*, i8** %4
%49 = call i64 @stat(i8* %48, %struct.stat* %8)
%50 = icmp ne i64 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %47
%52 = load i8*, i8** %4
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %52)
store i32 3, i32* %3
br label %131
54: ; preds = %47
%55 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%56 = call i64 @atol(i8* %55)
%57 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%58 = load i64, i64* %57
%59 = icmp eq i64 %56, %58
br i1 %59, label %60, label %71
60: ; preds = %54
%61 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%62 = call i64 @atol(i8* %61)
%63 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 1
%64 = load i64, i64* %63
%65 = icmp sgt i64 %62, %64
br i1 %65, label %66, label %71
66: ; preds = %60
store i64 0, i64* %12
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%68 = load i8*, i8** %4
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.5, i64 0, i64 0), i8* %68)
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.6, i64 0, i64 0))
br label %71
71: ; preds = %66, %60, %54
%72 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%73 = call i64 @atol(i8* %72)
%74 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%75 = load i64, i64* %74
%76 = icmp ne i64 %73, %75
br i1 %76, label %83, label %77
77: ; preds = %71
%78 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%79 = call i64 @atol(i8* %78)
%80 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 1
%81 = load i64, i64* %80
%82 = icmp sgt i64 %79, %81
br i1 %82, label %83, label %84
83: ; preds = %77, %71
store i64 0, i64* %12
br label %87
84: ; preds = %77
%85 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%86 = call i64 @atol(i8* %85)
store i64 %86, i64* %12
br label %87
87: ; preds = %84, %83
%88 = load i32*, i32** %6
%89 = load i64, i64* %12
%90 = call i32 @fseek(i32* %88, i64 %89, i32 0)
br label %91
91: ; preds = %96, %87
%92 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%93 = load i32*, i32** %6
%94 = call i32* @fgets(i8* %92, i32 1024, i32* %93)
%95 = icmp ne i32* %94, null
br i1 %95, label %96, label %99
96: ; preds = %91
%97 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%98 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* %97)
br label %91
99: ; preds = %91
%100 = load i8*, i8** %5
%101 = call i32* @fopen(i8* %100, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
store i32* %101, i32** %7
%102 = icmp eq i32* %101, null
br i1 %102, label %103, label %110
103: ; preds = %99
%104 = load i8*, i8** %5
%105 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.9, i64 0, i64 0), i8* %104)
%106 = load i32*, i32** %6
%107 = call i32 @fclose(i32* %106)
%108 = load i32*, i32** %7
%109 = call i32 @fclose(i32* %108)
store i32 4, i32* %3
br label %131
110: ; preds = %99
%111 = load i8*, i8** %5
%112 = call i64 @chmod(i8* %111, i32 384)
%113 = icmp ne i64 %112, 0
br i1 %113, label %114, label %117
114: ; preds = %110
%115 = load i8*, i8** %5
%116 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.10, i64 0, i64 0), i8* %115)
store i32 3, i32* %3
br label %131
117: ; preds = %110
%118 = load i32*, i32** %6
%119 = call i64 @ftell(i32* %118)
store i64 %119, i64* %12
%120 = load i32*, i32** %7
%121 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%122 = load i64, i64* %121
%123 = load i64, i64* %12
%124 = call i32 @fprintf(i32* %120, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0), i64 %122, i64 %123)
br label %125
125: ; preds = %117
br label %126
126: ; preds = %125
%127 = load i32*, i32** %6
%128 = call i32 @fclose(i32* %127)
%129 = load i32*, i32** %7
%130 = call i32 @fclose(i32* %129)
store i32 0, i32* %3
br label %131
131: ; preds = %126, %114, %103, %51, %16
%132 = load i32, i32* %3
ret i32 %132
}

LLVM IR (-O2):
%struct.stat = type { i64, i64 }
@.str = [3 x i8] c"rb\00"
@.str.1 = [25 x i8] c"File %s cannot be read.\0A\00"
@.str.2 = [2 x i8] c"0\00"
@.str.3 = [26 x i8] c"Cannot get %s file size.\0A\00"
@.str.5 = [65 x i8] c"*** WARNING ***: Log file %s is smaller than last time checked!\0A\00"
@.str.7 = [3 x i8] c"%s\00"
@.str.8 = [2 x i8] c"w\00"
@.str.9 = [52 x i8] c"File %s cannot be created. Check your permissions.\0A\00"
@.str.10 = [35 x i8] c"Cannot set permissions on file %s\0A\00"
@.str.11 = [8 x i8] c"%ld\0A%ld\00"
@str = [16 x i8] c"***************\00"
@str.12 = [48 x i8] c"***************\09 This could indicate tampering.\00"
define i32 @check_log(i8* %0, i8* %1) {
%3 = alloca %struct.stat
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = alloca [1024 x i8]
%7 = bitcast %struct.stat* %3 to i8*
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%11 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %89
15: ; preds = %2
%16 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %30, label %18
18: ; preds = %15
%19 = call i32* @fgets(i8* %10, i32 1024, i32* %16)
%20 = icmp eq i32* %19, null
br i1 %20, label %23, label %21
21: ; preds = %18
%22 = call i32 @strcpy(i8* %8, i8* %10)
br label %23
23: ; preds = %21, %18
%24 = call i32* @fgets(i8* %10, i32 1024, i32* %16)
%25 = icmp eq i32* %24, null
br i1 %25, label %28, label %26
26: ; preds = %23
%27 = call i32 @strcpy(i8* %9, i8* %10)
br label %28
28: ; preds = %26, %23
%29 = call i32 @fclose(i32* %16)
br label %32
30: ; preds = %15
%31 = call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %32
32: ; preds = %30, %28
%33 = call i64 @stat(i8* %0, %struct.stat* %3)
%34 = icmp eq i64 %33, 0
br i1 %34, label %37, label %35
35: ; preds = %32
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %89
37: ; preds = %32
%38 = call i64 @atol(i8* %8)
%39 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%40 = load i64, i64* %39
%41 = icmp eq i64 %38, %40
br i1 %41, label %42, label %52
42: ; preds = %37
%43 = call i64 @atol(i8* %9)
%44 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 1
%45 = load i64, i64* %44
%46 = icmp sgt i64 %43, %45
br i1 %46, label %47, label %52
47: ; preds = %42
%48 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @.str.5, i64 0, i64 0), i8* %0)
%50 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str.12, i64 0, i64 0))
%51 = load i64, i64* %39
br label %52
52: ; preds = %47, %42, %37
%53 = phi i64 [ %51, %47 ], [ %38, %42 ], [ %40, %37 ]
%54 = call i64 @atol(i8* %8)
%55 = icmp eq i64 %54, %53
br i1 %55, label %56, label %62
56: ; preds = %52
%57 = call i64 @atol(i8* %9)
%58 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 1
%59 = load i64, i64* %58
%60 = icmp sgt i64 %57, %59
%61 = select i1 %60, i64 0, i64 %57
br label %62
62: ; preds = %56, %52
%63 = phi i64 [ 0, %52 ], [ %61, %56 ]
%64 = call i32 @fseek(i32* %11, i64 %63, i32 0)
%65 = call i32* @fgets(i8* %10, i32 1024, i32* %11)
%66 = icmp eq i32* %65, null
br i1 %66, label %71, label %67
67: ; preds = %62, %67
%68 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* %10)
%69 = call i32* @fgets(i8* %10, i32 1024, i32* %11)
%70 = icmp eq i32* %69, null
br i1 %70, label %71, label %67
71: ; preds = %67, %62
%72 = call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%73 = icmp eq i32* %72, null
br i1 %73, label %74, label %78
74: ; preds = %71
%75 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.9, i64 0, i64 0), i8* %1)
%76 = call i32 @fclose(i32* %11)
%77 = call i32 @fclose(i32* null)
br label %89
78: ; preds = %71
%79 = call i64 @chmod(i8* %1, i32 384)
%80 = icmp eq i64 %79, 0
br i1 %80, label %83, label %81
81: ; preds = %78
%82 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.10, i64 0, i64 0), i8* %1)
br label %89
83: ; preds = %78
%84 = call i64 @ftell(i32* %11)
%85 = load i64, i64* %39
%86 = call i32 @fprintf(i32* %72, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0), i64 %85, i64 %84)
%87 = call i32 @fclose(i32* %11)
%88 = call i32 @fclose(i32* %72)
br label %89
89: ; preds = %83, %81, %74, %35, %13
%90 = phi i32 [ 2, %13 ], [ 3, %35 ], [ 4, %74 ], [ 3, %81 ], [ 0, %83 ]
ret i32 %90
}