#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 scalar_t__ ssize_t;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int O_CREAT;
int O_TRUNC;
int O_WRONLY;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ close(int);
int open(char const *, int, int);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int /*<<< orphan*/ strlen(char *);
scalar_t__ write(int, char *, int /*<<< orphan*/);
bool _q_countsave(const char *filepath, int number) {
  int fd = open(filepath, O_CREAT | O_WRONLY | O_TRUNC,
                (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH));
  if (fd < 0)
    return false;
  char buf[10 + 1];
  snprintf(buf, sizeof(buf), "%d", number);
  ssize_t updated = write(fd, buf, strlen(buf));
  close(fd);
  if (updated > 0)
    return true;
  return false;
}


x86 assembly (clang, -O0):
<_q_countsave>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e8e(%rip),%rax
mov    (%rax),%esi
mov    0x2e35(%rip),%rax
or     (%rax),%esi
mov    0x2e74(%rip),%rax
or     (%rax),%esi
mov    0x2e33(%rip),%rax
mov    (%rax),%edx
mov    0x2e4a(%rip),%rax
or     (%rax),%edx
mov    0x2e31(%rip),%rax
or     (%rax),%edx
mov    0x2e20(%rip),%rax
or     (%rax),%edx
call   1070 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11c0 <_q_countsave+0x70>
movl   $0x0,-0x4(%rbp)
jmp    1227 <_q_countsave+0xd7>
lea    -0x23(%rbp),%rdi
mov    -0x14(%rbp),%ecx
mov    $0xb,%esi
lea    0xe2d(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x3c(%rbp)
lea    -0x23(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    -0x23(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
cmpq   $0x0,-0x30(%rbp)
jle    1220 <_q_countsave+0xd0>
movl   $0x1,-0x4(%rbp)
jmp    1227 <_q_countsave+0xd7>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_q_countsave>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e99(%rip),%rcx
mov    0x2e42(%rip),%rax
mov    (%rax),%eax
or     (%rcx),%eax
mov    0x2e7f(%rip),%rcx
or     (%rcx),%eax
mov    0x2e3e(%rip),%rcx
mov    0x2e57(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    0x2e3c(%rip),%rcx
or     (%rcx),%edx
mov    %esi,%ebp
mov    0x2e29(%rip),%rcx
or     (%rcx),%edx
mov    %eax,%esi
call   1070 <open@plt>
test   %eax,%eax
js     11e9 <_q_countsave+0x99>
mov    %eax,%ebx
lea    0xe53(%rip),%rdx
lea    0x5(%rsp),%r14
mov    %r14,%rdi
mov    $0xb,%esi
mov    %ebp,%ecx
call   1050 <snprintf@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %rax,%rbp
mov    %ebx,%edi
call   1060 <close@plt>
xor    %eax,%eax
test   %rbp,%rbp
setg   %al
jmp    11eb <_q_countsave+0x9b>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str = [3 x i8] c"%d\00"
define i32 @_q_countsave(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca [11 x i8]
%8 = alloca i64
store i8* %0, i8** %4
store i32 %1, i32* %5
%9 = load i8*, i8** %4
%10 = load i32, i32* @O_CREAT
%11 = load i32, i32* @O_WRONLY
%12 = or i32 %10, %11
%13 = load i32, i32* @O_TRUNC
%14 = or i32 %12, %13
%15 = load i32, i32* @S_IRUSR
%16 = load i32, i32* @S_IWUSR
%17 = or i32 %15, %16
%18 = load i32, i32* @S_IRGRP
%19 = or i32 %17, %18
%20 = load i32, i32* @S_IROTH
%21 = or i32 %19, %20
%22 = call i32 @open(i8* %9, i32 %14, i32 %21)
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %2
store i32 0, i32* %3
br label %41
26: ; preds = %2
%27 = getelementptr inbounds [11 x i8], [11 x i8]* %7, i64 0, i64 0
%28 = load i32, i32* %5
%29 = call i32 @snprintf(i8* %27, i32 11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %28)
%30 = load i32, i32* %6
%31 = getelementptr inbounds [11 x i8], [11 x i8]* %7, i64 0, i64 0
%32 = getelementptr inbounds [11 x i8], [11 x i8]* %7, i64 0, i64 0
%33 = call i32 @strlen(i8* %32)
%34 = call i64 @write(i32 %30, i8* %31, i32 %33)
store i64 %34, i64* %8
%35 = load i32, i32* %6
%36 = call i32 @close(i32 %35)
%37 = load i64, i64* %8
%38 = icmp sgt i64 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %26
store i32 1, i32* %3
br label %41
40: ; preds = %26
store i32 0, i32* %3
br label %41
41: ; preds = %40, %39, %25
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str = [3 x i8] c"%d\00"
define i32 @_q_countsave(i8* nocapture %0, i32 %1) {
%3 = alloca [11 x i8]
%4 = load i32, i32* @O_CREAT
%5 = load i32, i32* @O_WRONLY
%6 = or i32 %5, %4
%7 = load i32, i32* @O_TRUNC
%8 = or i32 %6, %7
%9 = load i32, i32* @S_IRUSR
%10 = load i32, i32* @S_IWUSR
%11 = or i32 %10, %9
%12 = load i32, i32* @S_IRGRP
%13 = or i32 %11, %12
%14 = load i32, i32* @S_IROTH
%15 = or i32 %13, %14
%16 = tail call i32 @open(i8* %0, i32 %8, i32 %15)
%17 = icmp slt i32 %16, 0
br i1 %17, label %26, label %18
18: ; preds = %2
%19 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 0
%20 = call i32 @snprintf(i8* %19, i32 11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %1)
%21 = call i32 @strlen(i8* %19)
%22 = call i64 @write(i32 %16, i8* %19, i32 %21)
%23 = call i32 @close(i32 %16)
%24 = icmp sgt i64 %22, 0
%25 = zext i1 %24 to i32
br label %26
26: ; preds = %2, %18
%27 = phi i32 [ %25, %18 ], [ 0, %2 ]
ret i32 %27
}