#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*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int main(int argc, char **argv) {
  char buf[80], *p = malloc(128);
  FILE *f = fopen(argv[1], "r");
  fgets(buf, sizeof buf, f);
  free(p);
  if (buf[8] == 'P')
    *p = 5;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x80,%edi
call   1050 <malloc@plt>
mov    %rax,-0x68(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe8d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x70(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x70(%rbp),%rdx
mov    $0x50,%esi
call   1040 <fgets@plt>
mov    -0x68(%rbp),%rdi
call   1030 <free@plt>
movsbl -0x58(%rbp),%eax
cmp    $0x50,%eax
jne    11ab <main+0x6b>
mov    -0x68(%rbp),%rax
movb   $0x5,(%rax)
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x58,%rsp
mov    %rsi,%rbx
mov    $0x80,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    0x8(%rbx),%rdi
lea    0xe9e(%rip),%rsi
call   1060 <fopen@plt>
mov    %rsp,%rdi
mov    $0x50,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
mov    %r14,%rdi
call   1030 <free@plt>
cmpb   $0x50,0x8(%rsp)
jne    118a <main+0x4a>
movb   $0x5,(%r14)
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [80 x i8]
%7 = alloca i8*
%8 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i8* @malloc(i32 128)
store i8* %9, i8** %7
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %8
%14 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%15 = load i32*, i32** %8
%16 = call i32 @fgets(i8* %14, i32 80, i32* %15)
%17 = load i8*, i8** %7
%18 = call i32 @free(i8* %17)
%19 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 8
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 80
br i1 %22, label %23, label %25
23: ; preds = %2
%24 = load i8*, i8** %7
store i8 5, i8* %24
br label %25
25: ; preds = %23, %2
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [80 x i8]
%4 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%5 = tail call dereferenceable_or_null(128) i8* @malloc(i32 128)
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @fgets(i8* %4, i32 80, i32* %8)
%10 = call i32 @free(i8* %5)
%11 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 8
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 80
br i1 %13, label %14, label %15
14: ; preds = %2
store i8 5, i8* %5
br label %15
15: ; preds = %14, %2
ret i32 0
}