#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*/ SEEK_END;
int /*<<< orphan*/ __llvm_profile_is_continuous_mode_enabled();
int /*<<< orphan*/ __llvm_profile_set_file_object(int /*<<< orphan*/ *,
                                                  int /*<<< orphan*/);
scalar_t__ __llvm_profile_write_file();
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  if (!__llvm_profile_is_continuous_mode_enabled())
    return 1;
  FILE *f = fopen(argv[1], "a+b");
  if (!f)
    return 1;
  __llvm_profile_set_file_object(f, 0);
  if (__llvm_profile_write_file() != 0)
    return 1;
  f = fopen(argv[1], "r");
  if (!f)
    return 1;
  fseek(f, 0, SEEK_END);
  return ftell(f);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1060 <__llvm_profile_is_continuous_mode_enabled@plt>
cmp    $0x0,%eax
jne    1192 <main+0x32>
movl   $0x1,-0x4(%rbp)
jmp    1238 <main+0xd8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe5f(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c1 <main+0x61>
movl   $0x1,-0x4(%rbp)
jmp    1238 <main+0xd8>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1030 <__llvm_profile_set_file_object@plt>
mov    $0x0,%al
call   1080 <__llvm_profile_write_file@plt>
cmp    $0x0,%rax
je     11e9 <main+0x89>
movl   $0x1,-0x4(%rbp)
jmp    1238 <main+0xd8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe0c(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1218 <main+0xb8>
movl   $0x1,-0x4(%rbp)
jmp    1238 <main+0xd8>
mov    -0x18(%rbp),%rdi
mov    0x2dc5(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1040 <ftell@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    %rsi,%rbx
xor    %eax,%eax
call   1060 <__llvm_profile_is_continuous_mode_enabled@plt>
test   %eax,%eax
je     119a <main+0x3a>
mov    0x8(%rbx),%rdi
lea    0xe86(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     119a <main+0x3a>
mov    %rax,%rdi
xor    %esi,%esi
call   1030 <__llvm_profile_set_file_object@plt>
xor    %eax,%eax
call   1080 <__llvm_profile_write_file@plt>
test   %rax,%rax
je     11a1 <main+0x41>
mov    $0x1,%eax
pop    %rbx
ret
mov    0x8(%rbx),%rdi
lea    0xe58(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     119a <main+0x3a>
mov    %rax,%rbx
mov    0x2e28(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <fseek@plt>
mov    %rbx,%rdi
pop    %rbx
jmp    1040 <ftell@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"a+b\00"
@.str.1 = [2 x i8] c"r\00"
@SEEK_END = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i32 (...) @__llvm_profile_is_continuous_mode_enabled()
%8 = icmp ne i32 %7, 0
br i1 %8, label %10, label %9
9: ; preds = %2
store i32 1, i32* %3
br label %38
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %6
%15 = load i32*, i32** %6
%16 = icmp ne i32* %15, null
br i1 %16, label %18, label %17
17: ; preds = %10
store i32 1, i32* %3
br label %38
18: ; preds = %10
%19 = load i32*, i32** %6
%20 = call i32 @__llvm_profile_set_file_object(i32* %19, i32 0)
%21 = call i64 (...) @__llvm_profile_write_file()
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %18
store i32 1, i32* %3
br label %38
24: ; preds = %18
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32* @fopen(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %28, i32** %6
%29 = load i32*, i32** %6
%30 = icmp ne i32* %29, null
br i1 %30, label %32, label %31
31: ; preds = %24
store i32 1, i32* %3
br label %38
32: ; preds = %24
%33 = load i32*, i32** %6
%34 = load i32, i32* @SEEK_END
%35 = call i32 @fseek(i32* %33, i32 0, i32 %34)
%36 = load i32*, i32** %6
%37 = call i32 @ftell(i32* %36)
store i32 %37, i32* %3
br label %38
38: ; preds = %32, %31, %23, %17, %9
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@.str = [4 x i8] c"a+b\00"
@.str.1 = [2 x i8] c"r\00"
@SEEK_END = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 (...) @__llvm_profile_is_continuous_mode_enabled()
%4 = icmp eq i32 %3, 0
br i1 %4, label %22, label %5
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32* @fopen(i8* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %22, label %10
10: ; preds = %5
%11 = tail call i32 @__llvm_profile_set_file_object(i32* %8, i32 0)
%12 = tail call i64 (...) @__llvm_profile_write_file()
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %22
14: ; preds = %10
%15 = load i8*, i8** %6
%16 = tail call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %22, label %18
18: ; preds = %14
%19 = load i32, i32* @SEEK_END
%20 = tail call i32 @fseek(i32* %16, i32 0, i32 %19)
%21 = tail call i32 @ftell(i32* %16)
br label %22
22: ; preds = %18, %5, %10, %14, %2
%23 = phi i32 [ 1, %2 ], [ %21, %18 ], [ 1, %5 ], [ 1, %10 ], [ 1, %14 ]
ret i32 %23
}