#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  FILE *f = fopen(argv[1], "r+");
  if (f != NULL) {
    rewind(f);
    fputc(0xFF, f);
    fclose(f);
  } else {
    perror("Unable to modify cnt");
    return 1;
  }
  return 0;
}


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    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe8b(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11ae <main+0x5e>
mov    -0x18(%rbp),%rdi
call   1040 <rewind@plt>
mov    -0x18(%rbp),%rsi
mov    $0xff,%edi
call   1050 <fputc@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
jmp    11c6 <main+0x76>
lea    0xe4e(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11cd <main+0x7d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x8(%rsi),%rdi
lea    0xea4(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     118a <main+0x3a>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <rewind@plt>
mov    $0xff,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe72(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"r+\00"
@.str.1 = [21 x i8] c"Unable to modify cnt\00"
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 = load i8**, i8*** %5
%8 = getelementptr inbounds i8*, i8** %7, i64 1
%9 = load i8*, i8** %8
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %6
%11 = load i32*, i32** %6
%12 = icmp ne i32* %11, null
br i1 %12, label %13, label %20
13: ; preds = %2
%14 = load i32*, i32** %6
%15 = call i32 @rewind(i32* %14)
%16 = load i32*, i32** %6
%17 = call i32 @fputc(i32 255, i32* %16)
%18 = load i32*, i32** %6
%19 = call i32 @fclose(i32* %18)
br label %22
20: ; preds = %2
%21 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %23
22: ; preds = %13
store i32 0, i32* %3
br label %23
23: ; preds = %22, %20
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
@.str = [3 x i8] c"r+\00"
@.str.1 = [21 x i8] c"Unable to modify cnt\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = tail call i32* @fopen(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %11, label %7
7: ; preds = %2
%8 = tail call i32 @rewind(i32* %5)
%9 = tail call i32 @fputc(i32 255, i32* %5)
%10 = tail call i32 @fclose(i32* %5)
br label %13
11: ; preds = %2
%12 = tail call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %7, %11
%14 = phi i32 [ 0, %7 ], [ 1, %11 ]
ret i32 %14
}