#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 O_CREAT;
int O_RDWR;
int O_TRUNC;
int /*<<< orphan*/ close(int);
int open(char *, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
scalar_t__ strlen(char *);
int /*<<< orphan*/ write(int, char *, scalar_t__);
void write_expire_cnt(int v) {
  int fd;
  char str[25];
  sprintf(str, "%d", v);
  fd = open("/tmp/heartbeat", O_RDWR | O_CREAT | O_TRUNC);
  write(fd, str, strlen(str) + 1);
  close(fd);
}


x86 assembly (clang, -O0):
<write_expire_cnt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe97(%rip),%rsi
call   1070 <sprintf@plt>
mov    0x2e63(%rip),%rax
mov    (%rax),%esi
mov    0x2e7a(%rip),%rax
or     (%rax),%esi
mov    0x2e69(%rip),%rax
or     (%rax),%esi
lea    0xe73(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x3c(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_expire_cnt>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
mov    %edi,%edx
lea    0xea1(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1070 <sprintf@plt>
mov    0x2e67(%rip),%rax
mov    0x2e80(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e6d(%rip),%rax
or     (%rax),%esi
lea    0xe77(%rip),%rdi
call   1060 <open@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1030 <write@plt>
mov    %ebp,%edi
add    $0x28,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <close@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [15 x i8] c"/tmp/heartbeat\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
define void @write_expire_cnt(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [25 x i8]
store i32 %0, i32* %2
%5 = getelementptr inbounds [25 x i8], [25 x i8]* %4, i64 0, i64 0
%6 = load i32, i32* %2
%7 = call i32 @sprintf(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = load i32, i32* @O_RDWR
%9 = load i32, i32* @O_CREAT
%10 = or i32 %8, %9
%11 = load i32, i32* @O_TRUNC
%12 = or i32 %10, %11
%13 = call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %12)
store i32 %13, i32* %3
%14 = load i32, i32* %3
%15 = getelementptr inbounds [25 x i8], [25 x i8]* %4, i64 0, i64 0
%16 = getelementptr inbounds [25 x i8], [25 x i8]* %4, i64 0, i64 0
%17 = call i64 @strlen(i8* %16)
%18 = add nsw i64 %17, 1
%19 = call i32 @write(i32 %14, i8* %15, i64 %18)
%20 = load i32, i32* %3
%21 = call i32 @close(i32 %20)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [15 x i8] c"/tmp/heartbeat\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
define void @write_expire_cnt(i32 %0) {
%2 = alloca [25 x i8]
%3 = getelementptr inbounds [25 x i8], [25 x i8]* %2, i64 0, i64 0
%4 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %0)
%5 = load i32, i32* @O_RDWR
%6 = load i32, i32* @O_CREAT
%7 = or i32 %6, %5
%8 = load i32, i32* @O_TRUNC
%9 = or i32 %7, %8
%10 = tail call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = call i64 @strlen(i8* %3)
%12 = add nsw i64 %11, 1
%13 = call i32 @write(i32 %10, i8* %3, i64 %12)
%14 = tail call i32 @close(i32 %10)
ret void
}