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

/* Variables and functions */
int /*<<< orphan*/ S_ISREG(int /*<<< orphan*/);
int /*<<< orphan*/ chk_t(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
scalar_t__ stat(char *, struct stat *);
void init_counted_file(char *counted_file_path) {
  struct stat s;
  if (stat(counted_file_path, &s)) {
    FILE *counted_file_fd;
    counted_file_fd = fopen(counted_file_path, "w+");
    fwrite("0", 1, 1, counted_file_fd);
    fclose(counted_file_fd);
  } else {
    chk_t(
        S_ISREG(s.st_mode),
        "Error: the counted file %s already exists but is not a regular file\n",
        counted_file_path);
  }
}


x86 assembly (clang, -O0):
<init_counted_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0x0,%rax
je     11bc <init_counted_file+0x5c>
mov    -0x8(%rbp),%rdi
lea    0xe72(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rcx
lea    0xe61(%rip),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1080 <fwrite@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
jmp    11d6 <init_counted_file+0x76>
mov    -0x10(%rbp),%edi
call   1050 <S_ISREG@plt>
mov    %eax,%edi
mov    -0x8(%rbp),%rdx
lea    0xe34(%rip),%rsi
call   1060 <chk_t@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_counted_file>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
call   1050 <stat@plt>
test   %rax,%rax
je     11a0 <init_counted_file+0x40>
lea    0xe82(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
mov    %rax,%rbx
mov    $0x30,%edi
mov    %rax,%rsi
call   1040 <fputc@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    11ba <init_counted_file+0x5a>
mov    0x8(%rsp),%edi
call   1060 <S_ISREG@plt>
lea    0xe53(%rip),%rsi
mov    %eax,%edi
mov    %rbx,%rdx
call   1070 <chk_t@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [3 x i8] c"w+\00"
@.str.1 = [2 x i8] c"0\00"
@.str.2 = [69 x i8] c"Error: the counted file %s already exists but is not a regular file\0A\00"
define void @init_counted_file(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.stat
%4 = alloca i32*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i64 @stat(i8* %5, %struct.stat* %3)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %15
8: ; preds = %1
%9 = load i8*, i8** %2
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %4
%11 = load i32*, i32** %4
%12 = call i32 @fwrite(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1, i32 1, i32* %11)
%13 = load i32*, i32** %4
%14 = call i32 @fclose(i32* %13)
br label %21
15: ; preds = %1
%16 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%17 = load i32, i32* %16
%18 = call i32 @S_ISREG(i32 %17)
%19 = load i8*, i8** %2
%20 = call i32 @chk_t(i32 %18, i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.2, i64 0, i64 0), i8* %19)
br label %21
21: ; preds = %15, %8
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [3 x i8] c"w+\00"
@.str.2 = [69 x i8] c"Error: the counted file %s already exists but is not a regular file\0A\00"
define void @init_counted_file(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = call i64 @stat(i8* %0, %struct.stat* %2)
%5 = icmp eq i64 %4, 0
br i1 %5, label %10, label %6
6: ; preds = %1
%7 = call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @fputc(i32 48, i32* %7)
%9 = call i32 @fclose(i32* %7)
br label %15
10: ; preds = %1
%11 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%12 = load i32, i32* %11
%13 = call i32 @S_ISREG(i32 %12)
%14 = call i32 @chk_t(i32 %13, i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %15
15: ; preds = %10, %6
ret void
}