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

/* Variables and functions */
int /*<<< orphan*/ P();
int /*<<< orphan*/ V();
int atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ sleep(int);
void func_add() {
  FILE *fp;
  char buf[1024];
  fp = fopen("/tmp/out", "r+");
  if (fp == NULL) {
    perror("fopen()");
    exit(1);
  }
  P();
  fgets(buf, 1024, fp);
  rewind(fp);
  sleep(1);
  fprintf(fp, "%d\n", atoi(buf) + 1);
  fflush(fp);
  V();
  fclose(fp);
  return;
}


x86 assembly (clang, -O0):
<func_add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
lea    0xe2e(%rip),%rdi
lea    0xe30(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1203 <func_add+0x43>
lea    0xe18(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    $0x0,%al
call   1030 <P@plt>
lea    -0x410(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x400,%esi
call   1070 <fgets@plt>
mov    -0x8(%rbp),%rdi
call   1060 <rewind@plt>
mov    $0x1,%edi
call   10e0 <sleep@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x418(%rbp)
lea    -0x410(%rbp),%rdi
call   10c0 <atoi@plt>
mov    -0x418(%rbp),%rdi
mov    %eax,%edx
add    $0x1,%edx
lea    0xdb8(%rip),%rsi
call   1080 <fprintf@plt>
mov    -0x8(%rbp),%rdi
call   1090 <fflush@plt>
mov    $0x0,%al
call   1040 <V@plt>
mov    -0x8(%rbp),%rdi
call   1050 <fclose@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<func_add>:
push   %r14
push   %rbx
sub    $0x408,%rsp
lea    0xe2f(%rip),%rdi
lea    0xe31(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     124d <func_add+0x8d>
mov    %rax,%rbx
xor    %eax,%eax
call   1030 <P@plt>
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1070 <fgets@plt>
mov    %rbx,%rdi
call   1060 <rewind@plt>
mov    $0x1,%edi
call   10e0 <sleep@plt>
mov    %r14,%rdi
call   10c0 <atoi@plt>
lea    0x1(%rax),%edx
lea    0xdf1(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fprintf@plt>
mov    %rbx,%rdi
call   1090 <fflush@plt>
xor    %eax,%eax
call   1040 <V@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
add    $0x408,%rsp
pop    %rbx
pop    %r14
ret
lea    0xdb8(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"/tmp/out\00"
@.str.1 = [3 x i8] c"r+\00"
@.str.2 = [8 x i8] c"fopen()\00"
@.str.3 = [4 x i8] c"%d\0A\00"
define void @func_add() {
%1 = alloca i32*
%2 = alloca [1024 x i8]
%3 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %3, i32** %1
%4 = load i32*, i32** %1
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 @exit(i32 1)
unreachable
9: ; preds = %0
%10 = call i32 (...) @P()
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%12 = load i32*, i32** %1
%13 = call i32 @fgets(i8* %11, i32 1024, i32* %12)
%14 = load i32*, i32** %1
%15 = call i32 @rewind(i32* %14)
%16 = call i32 @sleep(i32 1)
%17 = load i32*, i32** %1
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%19 = call i32 @atoi(i8* %18)
%20 = add nsw i32 %19, 1
%21 = call i32 @fprintf(i32* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %20)
%22 = load i32*, i32** %1
%23 = call i32 @fflush(i32* %22)
%24 = call i32 (...) @V()
%25 = load i32*, i32** %1
%26 = call i32 @fclose(i32* %25)
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"/tmp/out\00"
@.str.1 = [3 x i8] c"r+\00"
@.str.2 = [8 x i8] c"fopen()\00"
@.str.3 = [4 x i8] c"%d\0A\00"
define void @func_add() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %0
%9 = tail call i32 (...) @P()
%10 = call i32 @fgets(i8* %2, i32 1024, i32* %3)
%11 = call i32 @rewind(i32* %3)
%12 = call i32 @sleep(i32 1)
%13 = call i32 @atoi(i8* %2)
%14 = add nsw i32 %13, 1
%15 = call i32 @fprintf(i32* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %14)
%16 = call i32 @fflush(i32* %3)
%17 = call i32 (...) @V()
%18 = call i32 @fclose(i32* %3)
ret void
}