#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 uint8_t;

/* Variables and functions */
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ LOG_NOTICE;
int /*<<< orphan*/ LOG_WARNING;
int /*<<< orphan*/ changelog_rotate();
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ meta_cleanup();
int meta_storeall(int /*<<< orphan*/);
scalar_t__ rename(char *, char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
char *strerr(int /*<<< orphan*/);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, ...);
void meta_term(void) {
  changelog_rotate();
  for (;;) {
    uint8_t status;
    status = meta_storeall(0);
    if (status == 1) {
      if (rename("metadata.mfs.back", "metadata.mfs") < 0) {
        {
          const char *_mfs_errstring = strerr(errno);
          syslog((LOG_WARNING), "%s: %s",
                 ("can't rename metadata.mfs.back -> metadata.mfs"),
                 _mfs_errstring);
          fprintf(stderr, "%s: %s\n",
                  ("can't rename metadata.mfs.back -> metadata.mfs"),
                  _mfs_errstring);
        };
      }
      meta_cleanup();
      return;
    } else if (status == 2) {
      {
        syslog((LOG_NOTICE), "%s", ("no metadata to store"));
        fprintf(stderr, "%s\n", ("no metadata to store"));
      };
      return;
    }
    syslog(LOG_ERR, "can't store metadata - try to make more space on your hdd "
                    "or change privieleges - retrying after 10 seconds");
    sleep(10);
  }
}


x86 assembly (clang, -O0):
<meta_term>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1030 <changelog_rotate@plt>
xor    %edi,%edi
call   1040 <meta_storeall@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x1,-0x4(%rbp)
jne    1222 <meta_term+0xa2>
lea    0xe56(%rip),%rdi
lea    0xe8a(%rip),%rsi
call   1070 <rename@plt>
cmp    $0x0,%rax
jge    1216 <meta_term+0x96>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
call   1090 <strerr@plt>
mov    %rax,-0x10(%rbp)
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rcx
lea    0xe2c(%rip),%rsi
lea    0xe2c(%rip),%rdx
mov    $0x0,%al
call   1060 <syslog@plt>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rcx
lea    0xe40(%rip),%rsi
lea    0xe0a(%rip),%rdx
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x0,%al
call   1080 <meta_cleanup@plt>
jmp    1298 <meta_term+0x118>
cmpl   $0x2,-0x4(%rbp)
jne    126d <meta_term+0xed>
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
lea    0xdda(%rip),%rsi
lea    0xe0d(%rip),%rdx
mov    $0x0,%al
call   1060 <syslog@plt>
mov    0x2d87(%rip),%rax
mov    (%rax),%edi
lea    0xdf2(%rip),%rsi
lea    0xdef(%rip),%rdx
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1298 <meta_term+0x118>
jmp    1272 <meta_term+0xf2>
mov    0x2d3f(%rip),%rax
mov    (%rax),%edi
lea    0xde3(%rip),%rsi
mov    $0x0,%al
call   1060 <syslog@plt>
mov    $0xa,%edi
call   10a0 <sleep@plt>
jmp    118f <meta_term+0xf>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<meta_term>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1030 <changelog_rotate@plt>
mov    0x2e26(%rip),%r14
lea    0xecc(%rip),%rbx
nopl   0x0(%rax)
xor    %edi,%edi
call   1040 <meta_storeall@plt>
cmp    $0x2,%eax
je     11ca <meta_term+0x4a>
cmp    $0x1,%eax
je     120c <meta_term+0x8c>
mov    (%r14),%edi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <syslog@plt>
mov    $0xa,%edi
call   10a0 <sleep@plt>
jmp    11a0 <meta_term+0x20>
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
lea    0xe3c(%rip),%rsi
lea    0xe6f(%rip),%rbx
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <syslog@plt>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
lea    0xe51(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <fprintf@plt>
lea    0xded(%rip),%rdi
lea    0xe21(%rip),%rsi
call   1070 <rename@plt>
test   %rax,%rax
jns    1276 <meta_term+0xf6>
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
call   1090 <strerr@plt>
mov    %rax,%rbx
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
lea    0xdcd(%rip),%rsi
lea    0xdcd(%rip),%r14
mov    %r14,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1060 <syslog@plt>
mov    0x2d78(%rip),%rax
mov    (%rax),%edi
lea    0xddf(%rip),%rsi
mov    %r14,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1080 <meta_cleanup@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"metadata.mfs.back\00"
@.str.1 = [13 x i8] c"metadata.mfs\00"
@errno = global i32 0
@LOG_WARNING = global i32 0
@.str.2 = [7 x i8] c"%s: %s\00"
@.str.3 = [47 x i8] c"can't rename metadata.mfs.back -> metadata.mfs\00"
@stderr = global i32 0
@.str.4 = [8 x i8] c"%s: %s\0A\00"
@LOG_NOTICE = global i32 0
@.str.5 = [3 x i8] c"%s\00"
@.str.6 = [21 x i8] c"no metadata to store\00"
@.str.7 = [4 x i8] c"%s\0A\00"
@LOG_ERR = global i32 0
@.str.8 = [108 x i8] c"can't store metadata - try to make more space on your hdd or change privieleges - retrying after 10 seconds\00"
define void @meta_term() {
%1 = alloca i32
%2 = alloca i8*
%3 = call i32 (...) @changelog_rotate()
br label %4
4: ; preds = %31, %0
%5 = call i32 @meta_storeall(i32 0)
store i32 %5, i32* %1
%6 = load i32, i32* %1
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %22
8: ; preds = %4
%9 = call i64 @rename(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %20
11: ; preds = %8
%12 = load i32, i32* @errno
%13 = call i8* @strerr(i32 %12)
store i8* %13, i8** %2
%14 = load i32, i32* @LOG_WARNING
%15 = load i8*, i8** %2
%16 = call i32 (i32, i8*, ...) @syslog(i32 %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i8* %15)
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %2
%19 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i8* %18)
br label %20
20: ; preds = %11, %8
%21 = call i32 (...) @meta_cleanup()
br label %35
22: ; preds = %4
%23 = load i32, i32* %1
%24 = icmp eq i32 %23, 2
br i1 %24, label %25, label %30
25: ; preds = %22
%26 = load i32, i32* @LOG_NOTICE
%27 = call i32 (i32, i8*, ...) @syslog(i32 %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
%28 = load i32, i32* @stderr
%29 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
br label %35
30: ; preds = %22
br label %31
31: ; preds = %30
%32 = load i32, i32* @LOG_ERR
%33 = call i32 (i32, i8*, ...) @syslog(i32 %32, i8* getelementptr inbounds ([108 x i8], [108 x i8]* @.str.8, i64 0, i64 0))
%34 = call i32 @sleep(i32 10)
br label %4
35: ; preds = %25, %20
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c"metadata.mfs.back\00"
@.str.1 = [13 x i8] c"metadata.mfs\00"
@errno = global i32 0
@LOG_WARNING = global i32 0
@.str.2 = [7 x i8] c"%s: %s\00"
@.str.3 = [47 x i8] c"can't rename metadata.mfs.back -> metadata.mfs\00"
@stderr = global i32 0
@.str.4 = [8 x i8] c"%s: %s\0A\00"
@LOG_NOTICE = global i32 0
@.str.5 = [3 x i8] c"%s\00"
@.str.6 = [21 x i8] c"no metadata to store\00"
@.str.7 = [4 x i8] c"%s\0A\00"
@LOG_ERR = global i32 0
@.str.8 = [108 x i8] c"can't store metadata - try to make more space on your hdd or change privieleges - retrying after 10 seconds\00"
define void @meta_term() {
%1 = tail call i32 (...) @changelog_rotate()
br label %2
2: ; preds = %21, %0
%3 = tail call i32 @meta_storeall(i32 0)
switch i32 %3, label %21 [
i32 1, label %4
i32 2, label %16
]
4: ; preds = %2
%5 = tail call i64 @rename(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %14
7: ; preds = %4
%8 = load i32, i32* @errno
%9 = tail call i8* @strerr(i32 %8)
%10 = load i32, i32* @LOG_WARNING
%11 = tail call i32 (i32, i8*, ...) @syslog(i32 %10, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i8* %9)
%12 = load i32, i32* @stderr
%13 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i8* %9)
br label %14
14: ; preds = %7, %4
%15 = tail call i32 (...) @meta_cleanup()
br label %25
16: ; preds = %2
%17 = load i32, i32* @LOG_NOTICE
%18 = tail call i32 (i32, i8*, ...) @syslog(i32 %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
%19 = load i32, i32* @stderr
%20 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
br label %25
21: ; preds = %2
%22 = load i32, i32* @LOG_ERR
%23 = tail call i32 (i32, i8*, ...) @syslog(i32 %22, i8* getelementptr inbounds ([108 x i8], [108 x i8]* @.str.8, i64 0, i64 0))
%24 = tail call i32 @sleep(i32 10)
br label %2
25: ; preds = %14, %16
ret void
}