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

/* Variables and functions */
scalar_t__ _bkp_logfile(char const *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ printf(char *);
scalar_t__ stat(char const *, struct stat *);
FILE *raspddns_init_log(const char *file) {
  struct stat fileinfo = {0};
  if (!file) {
    return NULL;
  }
  if (0 == stat(file, &fileinfo) && fileinfo.st_size > (3 * 1024 * 1024) &&
      0 != _bkp_logfile(file)) {
    printf("stat and move failed");
    return NULL;
  }
  FILE *p = fopen(file, "a");
  return p;
}


x86 assembly (clang, -O0):
<raspddns_init_log>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
cmpq   $0x0,-0x10(%rbp)
jne    1184 <raspddns_init_log+0x34>
movq   $0x0,-0x8(%rbp)
jmp    11f8 <raspddns_init_log+0xa8>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <stat@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    11dc <raspddns_init_log+0x8c>
cmpl   $0x300000,-0x18(%rbp)
jle    11dc <raspddns_init_log+0x8c>
mov    -0x10(%rbp),%rdi
call   1060 <_bkp_logfile@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     11dc <raspddns_init_log+0x8c>
lea    0xe36(%rip),%rdi
call   1030 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11f8 <raspddns_init_log+0xa8>
mov    -0x10(%rbp),%rdi
lea    0xe2e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<raspddns_init_log>:
push   %rbx
sub    $0x10,%rsp
movq   $0x0,0x8(%rsp)
test   %rdi,%rdi
je     1188 <raspddns_init_log+0x48>
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
call   1040 <stat@plt>
test   %rax,%rax
jne    118c <raspddns_init_log+0x4c>
cmpl   $0x300001,0x8(%rsp)
jl     118c <raspddns_init_log+0x4c>
mov    %rbx,%rdi
call   1050 <_bkp_logfile@plt>
test   %rax,%rax
je     118c <raspddns_init_log+0x4c>
lea    0xe7d(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
jmp    119b <raspddns_init_log+0x5b>
lea    0xe82(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.stat = type { i32, i32 }
@.str = [21 x i8] c"stat and move failed\00"
@.str.1 = [2 x i8] c"a\00"
define i32* @raspddns_init_log(i8* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca %struct.stat
%5 = alloca i32*
store i8* %0, i8** %3
%6 = bitcast %struct.stat* %4 to i8*
%7 = load i8*, i8** %3
%8 = icmp ne i8* %7, null
br i1 %8, label %10, label %9
9: ; preds = %1
store i32* null, i32** %2
br label %28
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = call i64 @stat(i8* %11, %struct.stat* %4)
%13 = icmp eq i64 0, %12
br i1 %13, label %14, label %24
14: ; preds = %10
%15 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%16 = load i32, i32* %15
%17 = icmp sgt i32 %16, 3145728
br i1 %17, label %18, label %24
18: ; preds = %14
%19 = load i8*, i8** %3
%20 = call i64 @_bkp_logfile(i8* %19)
%21 = icmp ne i64 0, %20
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
store i32* null, i32** %2
br label %28
24: ; preds = %18, %14, %10
%25 = load i8*, i8** %3
%26 = call i32* @fopen(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %26, i32** %5
%27 = load i32*, i32** %5
store i32* %27, i32** %2
br label %28
28: ; preds = %24, %22, %9
%29 = load i32*, i32** %2
ret i32* %29
}

LLVM IR (-O2):
%struct.stat = type { i32, i32 }
@.str = [21 x i8] c"stat and move failed\00"
@.str.1 = [2 x i8] c"a\00"
define noalias i32* @raspddns_init_log(i8* %0) {
%2 = alloca i64
%3 = bitcast i64* %2 to i8*
store i64 0, i64* %2
%4 = icmp eq i8* %0, null
br i1 %4, label %20, label %5
5: ; preds = %1
%6 = bitcast i64* %2 to %struct.stat*
%7 = call i64 @stat(i8* %0, %struct.stat* %6)
%8 = icmp eq i64 %7, 0
%9 = bitcast i64* %2 to i32*
%10 = load i32, i32* %9
%11 = icmp sgt i32 %10, 3145728
%12 = select i1 %8, i1 %11, i1 false
br i1 %12, label %13, label %18
13: ; preds = %5
%14 = call i64 @_bkp_logfile(i8* %0)
%15 = icmp eq i64 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %13
%17 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %20
18: ; preds = %13, %5
%19 = call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %1, %18, %16
%21 = phi i32* [ null, %16 ], [ %19, %18 ], [ null, %1 ]
ret i32* %21
}