#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 /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ assert(int);
int atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ err_sys(char *, char const *);
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char const *, int);
int read(int, char *, size_t);
int /*<<< orphan*/ sprintf(char *, char *, int);
int strlen(char *);
int /*<<< orphan*/ write(int, char *, int);
void increment(const char *msg, const char *filename) {
  assert(msg != NULL && filename != NULL);
  char buf[1024];
  size_t bufsize = 1024;
  int fd;
  if ((fd = open(filename, O_RDONLY)) < 0) {
    err_sys("error on opening file %s", filename);
  }
  int size = read(fd, buf, bufsize);
  buf[size] = '\0';
  close(fd);
  int n = atoi(buf);
  n++;
  sprintf(buf, "%d", n);
  size = strlen(buf);
  if ((fd = open(filename, O_WRONLY)) < 0) {
    err_sys("error on opening file %s", filename);
  }
  write(fd, buf, size);
  printf("%s with number = %d\n", msg, n);
  close(fd);
}


x86 assembly (clang, -O0):
<increment>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x8(%rbp)
mov    %al,-0x425(%rbp)
je     11d4 <increment+0x34>
cmpq   $0x0,-0x10(%rbp)
setne  %al
mov    %al,-0x425(%rbp)
mov    -0x425(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1090 <assert@plt>
movq   $0x400,-0x418(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2dee(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
mov    %eax,-0x41c(%rbp)
cmp    $0x0,%eax
jge    1220 <increment+0x80>
mov    -0x10(%rbp),%rsi
lea    0xde5(%rip),%rdi
call   1030 <err_sys@plt>
mov    -0x41c(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    -0x418(%rbp),%rdx
call   1080 <read@plt>
mov    %eax,-0x420(%rbp)
movslq -0x420(%rbp),%rax
movb   $0x0,-0x410(%rbp,%rax,1)
mov    -0x41c(%rbp),%edi
call   1070 <close@plt>
lea    -0x410(%rbp),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x424(%rbp)
mov    -0x424(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x424(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x424(%rbp),%edx
lea    0xd8b(%rip),%rsi
call   10c0 <sprintf@plt>
lea    -0x410(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x420(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2d20(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
mov    %eax,-0x41c(%rbp)
cmp    $0x0,%eax
jge    12d6 <increment+0x136>
mov    -0x10(%rbp),%rsi
lea    0xd2f(%rip),%rdi
call   1030 <err_sys@plt>
mov    -0x41c(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    -0x420(%rbp),%edx
call   1040 <write@plt>
mov    -0x8(%rbp),%rsi
mov    -0x424(%rbp),%edx
lea    0xd1d(%rip),%rdi
call   1060 <printf@plt>
mov    -0x41c(%rbp),%edi
call   1070 <close@plt>
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<increment>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
test   %rdi,%rdi
setne  %al
test   %rsi,%rsi
setne  %cl
and    %al,%cl
movzbl %cl,%edi
call   1090 <assert@plt>
mov    0x2e16(%rip),%rax
mov    (%rax),%esi
mov    %r15,%rdi
call   10a0 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    11f1 <increment+0x51>
lea    0xe17(%rip),%rdi
mov    %r15,%rsi
call   1030 <err_sys@plt>
mov    %rsp,%r12
mov    $0x400,%edx
mov    %ebx,%edi
mov    %r12,%rsi
call   1080 <read@plt>
cltq
movb   $0x0,(%rsp,%rax,1)
mov    %ebx,%edi
call   1070 <close@plt>
mov    %r12,%rdi
call   10b0 <atoi@plt>
mov    %eax,%ebp
add    $0x1,%ebp
lea    0xdf5(%rip),%rsi
mov    %r12,%rdi
mov    %ebp,%edx
call   10c0 <sprintf@plt>
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %eax,%r12d
mov    0x2d90(%rip),%rax
mov    (%rax),%esi
mov    %r15,%rdi
call   10a0 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    125f <increment+0xbf>
lea    0xda9(%rip),%rdi
mov    %r15,%rsi
call   1030 <err_sys@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    %r12d,%edx
call   1040 <write@plt>
lea    0xda9(%rip),%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1060 <printf@plt>
mov    %ebx,%edi
call   1070 <close@plt>
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@.str = [25 x i8] c"error on opening file %s\00"
@.str.1 = [3 x i8] c"%d\00"
@O_WRONLY = global i32 0
@.str.2 = [21 x i8] c"%s with number = %d\0A\00"
define void @increment(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [1024 x i8]
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%10 = load i8*, i8** %3
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = icmp ne i8* %13, null
br label %15
15: ; preds = %12, %2
%16 = phi i1 [ false, %2 ], [ %14, %12 ]
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
store i64 1024, i64* %6
%19 = load i8*, i8** %4
%20 = load i32, i32* @O_RDONLY
%21 = call i32 @open(i8* %19, i32 %20)
store i32 %21, i32* %7
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %15
%24 = load i8*, i8** %4
%25 = call i32 @err_sys(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %24)
br label %26
26: ; preds = %23, %15
%27 = load i32, i32* %7
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%29 = load i64, i64* %6
%30 = call i32 @read(i32 %27, i8* %28, i64 %29)
store i32 %30, i32* %8
%31 = load i32, i32* %8
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 %32
store i8 0, i8* %33
%34 = load i32, i32* %7
%35 = call i32 @close(i32 %34)
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%37 = call i32 @atoi(i8* %36)
store i32 %37, i32* %9
%38 = load i32, i32* %9
%39 = add nsw i32 %38, 1
store i32 %39, i32* %9
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%41 = load i32, i32* %9
%42 = call i32 @sprintf(i8* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %41)
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%44 = call i32 @strlen(i8* %43)
store i32 %44, i32* %8
%45 = load i8*, i8** %4
%46 = load i32, i32* @O_WRONLY
%47 = call i32 @open(i8* %45, i32 %46)
store i32 %47, i32* %7
%48 = icmp slt i32 %47, 0
br i1 %48, label %49, label %52
49: ; preds = %26
%50 = load i8*, i8** %4
%51 = call i32 @err_sys(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %50)
br label %52
52: ; preds = %49, %26
%53 = load i32, i32* %7
%54 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%55 = load i32, i32* %8
%56 = call i32 @write(i32 %53, i8* %54, i32 %55)
%57 = load i8*, i8** %3
%58 = load i32, i32* %9
%59 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %57, i32 %58)
%60 = load i32, i32* %7
%61 = call i32 @close(i32 %60)
ret void
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str = [25 x i8] c"error on opening file %s\00"
@.str.1 = [3 x i8] c"%d\00"
@O_WRONLY = global i32 0
@.str.2 = [21 x i8] c"%s with number = %d\0A\00"
define void @increment(i8* %0, i8* %1) {
%3 = alloca [1024 x i8]
%4 = icmp ne i8* %0, null
%5 = icmp ne i8* %1, null
%6 = and i1 %4, %5
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%10 = load i32, i32* @O_RDONLY
%11 = tail call i32 @open(i8* %1, i32 %10)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = tail call i32 @err_sys(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %15
15: ; preds = %13, %2
%16 = call i32 @read(i32 %11, i8* %9, i64 1024)
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %17
store i8 0, i8* %18
%19 = tail call i32 @close(i32 %11)
%20 = call i32 @atoi(i8* %9)
%21 = add nsw i32 %20, 1
%22 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%23 = call i32 @strlen(i8* %9)
%24 = load i32, i32* @O_WRONLY
%25 = call i32 @open(i8* %1, i32 %24)
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %15
%28 = call i32 @err_sys(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %29
29: ; preds = %27, %15
%30 = call i32 @write(i32 %25, i8* %9, i32 %23)
%31 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %0, i32 %21)
%32 = call i32 @close(i32 %25)
ret void
}