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

/* Variables and functions */
int NAME_MAX;
int PATH_MAX;
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ getenv(char *);
int isrunning(char **);
int /*<<< orphan*/ rotate(char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ strcpy(char *, int /*<<< orphan*/);
char *strdup(char *);
int main() {
  char pathname[PATH_MAX];
  char user[NAME_MAX], home[NAME_MAX];
  char *logfile, *errlog;
  strcpy(user, getenv("LOGNAME"));
  strcpy(home, getenv("HOME"));
  sprintf(pathname, "%s/log/backup.log", home);
  logfile = strdup(pathname);
  sprintf(pathname, "%s/log/errors.log", home);
  errlog = strdup(pathname);
  {
    char *prlist[4] = {"bulogrot", "backup", "cleanup", NULL};
    int res = isrunning(prlist);
    while (res > 1) {
      sleep(60);
      res = isrunning(prlist);
    }
  }
  rotate(logfile);
  rotate(errlog);
  free(errlog);
  free(logfile);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e57(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x70(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
mov    0x2e0b(%rip),%rax
mov    (%rax),%ecx
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x80(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x20(%rbp)
mov    (%rax),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x78(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
lea    0xdf8(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x80(%rbp),%rdi
mov    %eax,%esi
call   1050 <strcpy@plt>
lea    0xde9(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x78(%rbp),%rdi
mov    %eax,%esi
call   1050 <strcpy@plt>
mov    -0x78(%rbp),%rdx
mov    -0x70(%rbp),%rdi
lea    0xdcf(%rip),%rsi
call   1080 <sprintf@plt>
mov    -0x70(%rbp),%rdi
call   1090 <strdup@plt>
mov    -0x78(%rbp),%rdx
mov    -0x70(%rbp),%rdi
mov    %rax,-0x30(%rbp)
lea    0xdc0(%rip),%rsi
call   1080 <sprintf@plt>
mov    -0x70(%rbp),%rdi
call   1090 <strdup@plt>
mov    %rax,-0x38(%rbp)
mov    0x2b78(%rip),%rax
mov    %rax,-0x60(%rbp)
mov    0x2b75(%rip),%rax
mov    %rax,-0x58(%rbp)
mov    0x2b72(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0x2b6f(%rip),%rax
mov    %rax,-0x48(%rbp)
lea    -0x60(%rbp),%rdi
call   1070 <isrunning@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0x1,-0x64(%rbp)
jle    12ce <main+0x14e>
mov    $0x3c,%edi
call   10a0 <sleep@plt>
lea    -0x60(%rbp),%rdi
call   1070 <isrunning@plt>
mov    %eax,-0x64(%rbp)
jmp    12a9 <main+0x129>
mov    -0x30(%rbp),%rdi
call   1060 <rotate@plt>
mov    -0x38(%rbp),%rdi
call   1060 <rotate@plt>
mov    -0x38(%rbp),%rdi
call   1040 <free@plt>
mov    -0x30(%rbp),%rdi
call   1040 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    0x2e5a(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r15
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    0x2e20(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rsp,%r12
sub    %rax,%r12
mov    %r12,%rsp
lea    0xe2d(%rip),%rdi
call   1030 <getenv@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1050 <strcpy@plt>
lea    0xe1f(%rip),%rdi
call   1030 <getenv@plt>
mov    %r12,%rdi
mov    %eax,%esi
call   1050 <strcpy@plt>
lea    0xe0e(%rip),%rsi
mov    %r15,%rdi
mov    %r12,%rdx
call   1080 <sprintf@plt>
mov    %r15,%rdi
call   1090 <strdup@plt>
mov    %rax,%r14
lea    0xe03(%rip),%rsi
mov    %r15,%rdi
mov    %r12,%rdx
call   1080 <sprintf@plt>
mov    %r15,%rdi
call   1090 <strdup@plt>
mov    %rax,%r15
movaps 0x2bc7(%rip),%xmm0
movaps %xmm0,-0x30(%rbp)
movaps 0x2bac(%rip),%xmm0
movaps %xmm0,-0x40(%rbp)
lea    -0x40(%rbp),%rdi
call   1070 <isrunning@plt>
cmp    $0x2,%eax
jl     1277 <main+0xf7>
lea    -0x40(%rbp),%rbx
nopw   0x0(%rax,%rax,1)
mov    $0x3c,%edi
call   10a0 <sleep@plt>
mov    %rbx,%rdi
call   1070 <isrunning@plt>
cmp    $0x1,%eax
jg     1260 <main+0xe0>
mov    %r14,%rdi
call   1060 <rotate@plt>
mov    %r15,%rdi
call   1060 <rotate@plt>
mov    %r15,%rdi
call   1040 <free@plt>
mov    %r14,%rdi
call   1040 <free@plt>
xor    %eax,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@NAME_MAX = global i32 0
@.str = [8 x i8] c"LOGNAME\00"
@.str.1 = [5 x i8] c"HOME\00"
@.str.2 = [18 x i8] c"%s/log/backup.log\00"
@.str.3 = [18 x i8] c"%s/log/errors.log\00"
@.str.4 = [9 x i8] c"bulogrot\00"
@.str.5 = [7 x i8] c"backup\00"
@.str.6 = [8 x i8] c"cleanup\00"
@__const.main.prlist = [4 x i8*] [i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i32 0, i32 0), i8* null]
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca [4 x i8*]
%9 = alloca i32
store i32 0, i32* %1
%10 = load i32, i32* @PATH_MAX
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %2
%13 = alloca i8, i64 %11
store i64 %11, i64* %3
%14 = load i32, i32* @NAME_MAX
%15 = zext i32 %14 to i64
%16 = alloca i8, i64 %15
store i64 %15, i64* %4
%17 = load i32, i32* @NAME_MAX
%18 = zext i32 %17 to i64
%19 = alloca i8, i64 %18
store i64 %18, i64* %5
%20 = call i32 @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%21 = call i32 @strcpy(i8* %16, i32 %20)
%22 = call i32 @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%23 = call i32 @strcpy(i8* %19, i32 %22)
%24 = call i32 @sprintf(i8* %13, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %19)
%25 = call i8* @strdup(i8* %13)
store i8* %25, i8** %6
%26 = call i32 @sprintf(i8* %13, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %19)
%27 = call i8* @strdup(i8* %13)
store i8* %27, i8** %7
%28 = bitcast [4 x i8*]* %8 to i8*
%29 = getelementptr inbounds [4 x i8*], [4 x i8*]* %8, i64 0, i64 0
%30 = call i32 @isrunning(i8** %29)
store i32 %30, i32* %9
br label %31
31: ; preds = %34, %0
%32 = load i32, i32* %9
%33 = icmp sgt i32 %32, 1
br i1 %33, label %34, label %38
34: ; preds = %31
%35 = call i32 @sleep(i32 60)
%36 = getelementptr inbounds [4 x i8*], [4 x i8*]* %8, i64 0, i64 0
%37 = call i32 @isrunning(i8** %36)
store i32 %37, i32* %9
br label %31
38: ; preds = %31
%39 = load i8*, i8** %6
%40 = call i32 @rotate(i8* %39)
%41 = load i8*, i8** %7
%42 = call i32 @rotate(i8* %41)
%43 = load i8*, i8** %7
%44 = call i32 @free(i8* %43)
%45 = load i8*, i8** %6
%46 = call i32 @free(i8* %45)
store i32 0, i32* %1
%47 = load i8*, i8** %2
%48 = load i32, i32* %1
ret i32 %48
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@NAME_MAX = global i32 0
@.str = [8 x i8] c"LOGNAME\00"
@.str.1 = [5 x i8] c"HOME\00"
@.str.2 = [18 x i8] c"%s/log/backup.log\00"
@.str.3 = [18 x i8] c"%s/log/errors.log\00"
@.str.4 = [9 x i8] c"bulogrot\00"
@.str.5 = [7 x i8] c"backup\00"
@.str.6 = [8 x i8] c"cleanup\00"
@__const.main.prlist = [4 x i8*] [i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i32 0, i32 0), i8* null]
define i32 @main() {
%1 = alloca [4 x i8*]
%2 = load i32, i32* @PATH_MAX
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = load i32, i32* @NAME_MAX
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = alloca i8, i64 %6
%9 = tail call i32 @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @strcpy(i8* %7, i32 %9)
%11 = call i32 @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @strcpy(i8* %8, i32 %11)
%13 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%14 = call i8* @strdup(i8* %4)
%15 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %8)
%16 = call i8* @strdup(i8* %4)
%17 = bitcast [4 x i8*]* %1 to i8*
%18 = getelementptr inbounds [4 x i8*], [4 x i8*]* %1, i64 0, i64 0
%19 = call i32 @isrunning(i8** %18)
%20 = icmp sgt i32 %19, 1
br i1 %20, label %21, label %25
21: ; preds = %0, %21
%22 = call i32 @sleep(i32 60)
%23 = call i32 @isrunning(i8** %18)
%24 = icmp sgt i32 %23, 1
br i1 %24, label %21, label %25
25: ; preds = %21, %0
%26 = call i32 @rotate(i8* %14)
%27 = call i32 @rotate(i8* %16)
%28 = call i32 @free(i8* %16)
%29 = call i32 @free(i8* %14)
ret i32 0
}