#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 EOF;
int /*<<< orphan*/ assert(int);
scalar_t__ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fputc(char, int /*<<< orphan*/ *);
int fputs(char *, int /*<<< orphan*/ *);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
int fwrite(char *, int, int, int /*<<< orphan*/ *);
int strlen(char *);
int main(int argc, char const *argv[]) {
  FILE *fp;
  FILE *fp2;
  int x, y, z, w;
  char str[] = "test string";
  char c[] = "test string";
  char buffer[100];
  size_t a;
  for (int i = 0; i < 2; ++i) {
    fp = fopen("/home/akshay/Desktop/playground/inputfile.txt", "w");
    assert(fp != NULL);
    x = fwrite(str, 1, strlen(str) * sizeof(char), fp);
    assert(x > 0);
    fclose(fp);
    fp2 = fopen("/home/akshay/Desktop/playground/inputfile2.txt", "w+");
    y = fputs("hello world 1", fp2);
    assert(y != EOF);
    w = fgetc(fp2);
    assert(errno == 0);
    z = fputc('x', fp2);
    assert(z != EOF);
    fclose(fp2);
    fp = fopen("/home/akshay/Desktop/playground/inputfile.txt", "r");
    a = fread(buffer, strlen(c), 1, fp);
    assert(a != 0);
    fclose(fp);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe50(%rip),%rax
mov    %rax,-0x3c(%rbp)
mov    0xe4e(%rip),%eax
mov    %eax,-0x34(%rbp)
mov    0xe3c(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    0xe3a(%rip),%eax
mov    %eax,-0x40(%rbp)
movl   $0x0,-0xbc(%rbp)
cmpl   $0x2,-0xbc(%rbp)
jge    1377 <main+0x1e7>
lea    0xe1d(%rip),%rdi
lea    0xe44(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1090 <assert@plt>
lea    -0x3c(%rbp),%rax
mov    %rax,-0xd0(%rbp)
lea    -0x3c(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0xd0(%rbp),%rdi
cltq
shl    $0x0,%rax
mov    %eax,%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   10b0 <fwrite@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1090 <assert@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xdd6(%rip),%rdi
lea    0xdfe(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xded(%rip),%rdi
call   1060 <fputs@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    0x2d55(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1090 <assert@plt>
mov    -0x20(%rbp),%rdi
call   1070 <fgetc@plt>
mov    %eax,-0x30(%rbp)
mov    0x2d23(%rip),%rax
cmpq   $0x0,(%rax)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1090 <assert@plt>
mov    -0x20(%rbp),%rsi
mov    $0x78,%edi
call   1080 <fputc@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    0x2d07(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1090 <assert@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xd0c(%rip),%rdi
lea    0xd75(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    -0xb0(%rbp),%rax
mov    %rax,-0xc8(%rbp)
lea    -0x48(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0xc8(%rbp),%rdi
mov    %eax,%esi
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
call   1030 <fread@plt>
mov    %rax,-0xb8(%rbp)
cmpq   $0x0,-0xb8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1090 <assert@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0xbc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xbc(%rbp)
jmp    11db <main+0x4b>
xor    %eax,%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
movabs $0x7274732074736574,%rax
73 74 72
mov    %rax,0x10(%rsp)
movl   $0x676e69,0x18(%rsp)
mov    %rax,(%rsp)
movl   $0x676e69,0x8(%rsp)
lea    0xe41(%rip),%r14
lea    0xe68(%rip),%rsi
mov    %r14,%rdi
call   10a0 <fopen@plt>
mov    %rax,%rbp
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1090 <assert@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %rbp,%rcx
call   10b0 <fwrite@plt>
xor    %edi,%edi
test   %eax,%eax
setg   %dil
call   1090 <assert@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
lea    0xe16(%rip),%rdi
lea    0xe3e(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%rbp
lea    0xe32(%rip),%rdi
mov    %rax,%rsi
call   1060 <fputs@plt>
mov    0x2d9d(%rip),%r15
xor    %edi,%edi
cmp    (%r15),%eax
setne  %dil
call   1090 <assert@plt>
mov    %rbp,%rdi
call   1070 <fgetc@plt>
mov    0x2d70(%rip),%rax
xor    %edi,%edi
cmpq   $0x0,(%rax)
sete   %dil
call   1090 <assert@plt>
mov    $0x78,%edi
mov    %rbp,%rsi
call   1080 <fputc@plt>
xor    %edi,%edi
cmp    (%r15),%eax
setne  %dil
call   1090 <assert@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
lea    0xddb(%rip),%rsi
mov    %r14,%rdi
call   10a0 <fopen@plt>
mov    %rax,%rbp
mov    %rsp,%r12
mov    %r12,%rdi
call   1050 <strlen@plt>
lea    0x20(%rsp),%r13
mov    %r13,%rdi
mov    %eax,%esi
mov    $0x1,%edx
mov    %rbp,%rcx
call   1030 <fread@plt>
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1090 <assert@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
lea    0xd4c(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%rbp
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1090 <assert@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %rbp,%rcx
call   10b0 <fwrite@plt>
xor    %edi,%edi
test   %eax,%eax
setg   %dil
call   1090 <assert@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
lea    0xd02(%rip),%rdi
lea    0xd2a(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%rbx
lea    0xd1e(%rip),%rdi
mov    %rax,%rsi
call   1060 <fputs@plt>
xor    %edi,%edi
cmp    (%r15),%eax
setne  %dil
call   1090 <assert@plt>
mov    %rbx,%rdi
call   1070 <fgetc@plt>
xor    %edi,%edi
mov    0x2c61(%rip),%rax
cmpq   $0x0,(%rax)
sete   %dil
call   1090 <assert@plt>
mov    $0x78,%edi
mov    %rbx,%rsi
call   1080 <fputc@plt>
xor    %edi,%edi
cmp    (%r15),%eax
setne  %dil
call   1090 <assert@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
lea    0xccb(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%rbx
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %r13,%rdi
mov    %eax,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1090 <assert@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.str = [12 x i8] c"test string\00"
@__const.main.c = [12 x i8] c"test string\00"
@.str = [46 x i8] c"/home/akshay/Desktop/playground/inputfile.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [47 x i8] c"/home/akshay/Desktop/playground/inputfile2.txt\00"
@.str.3 = [3 x i8] c"w+\00"
@.str.4 = [14 x i8] c"hello world 1\00"
@EOF = global i32 0
@errno = global i64 0
@.str.5 = [2 x i8] c"r\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca [12 x i8]
%13 = alloca [12 x i8]
%14 = alloca [100 x i8]
%15 = alloca i64
%16 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = bitcast [12 x i8]* %12 to i8*
%18 = bitcast [12 x i8]* %13 to i8*
store i32 0, i32* %16
br label %19
19: ; preds = %77, %2
%20 = load i32, i32* %16
%21 = icmp slt i32 %20, 2
br i1 %21, label %22, label %80
22: ; preds = %19
%23 = call i32* @fopen(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %23, i32** %6
%24 = load i32*, i32** %6
%25 = icmp ne i32* %24, null
%26 = zext i1 %25 to i32
%27 = call i32 @assert(i32 %26)
%28 = getelementptr inbounds [12 x i8], [12 x i8]* %12, i64 0, i64 0
%29 = getelementptr inbounds [12 x i8], [12 x i8]* %12, i64 0, i64 0
%30 = call i32 @strlen(i8* %29)
%31 = sext i32 %30 to i64
%32 = mul i64 %31, 1
%33 = trunc i64 %32 to i32
%34 = load i32*, i32** %6
%35 = call i32 @fwrite(i8* %28, i32 1, i32 %33, i32* %34)
store i32 %35, i32* %8
%36 = load i32, i32* %8
%37 = icmp sgt i32 %36, 0
%38 = zext i1 %37 to i32
%39 = call i32 @assert(i32 %38)
%40 = load i32*, i32** %6
%41 = call i32 @fclose(i32* %40)
%42 = call i32* @fopen(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %42, i32** %7
%43 = load i32*, i32** %7
%44 = call i32 @fputs(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32* %43)
store i32 %44, i32* %9
%45 = load i32, i32* %9
%46 = load i32, i32* @EOF
%47 = icmp ne i32 %45, %46
%48 = zext i1 %47 to i32
%49 = call i32 @assert(i32 %48)
%50 = load i32*, i32** %7
%51 = call i32 @fgetc(i32* %50)
store i32 %51, i32* %11
%52 = load i64, i64* @errno
%53 = icmp eq i64 %52, 0
%54 = zext i1 %53 to i32
%55 = call i32 @assert(i32 %54)
%56 = load i32*, i32** %7
%57 = call i32 @fputc(i8 signext 120, i32* %56)
store i32 %57, i32* %10
%58 = load i32, i32* %10
%59 = load i32, i32* @EOF
%60 = icmp ne i32 %58, %59
%61 = zext i1 %60 to i32
%62 = call i32 @assert(i32 %61)
%63 = load i32*, i32** %7
%64 = call i32 @fclose(i32* %63)
%65 = call i32* @fopen(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %65, i32** %6
%66 = getelementptr inbounds [100 x i8], [100 x i8]* %14, i64 0, i64 0
%67 = getelementptr inbounds [12 x i8], [12 x i8]* %13, i64 0, i64 0
%68 = call i32 @strlen(i8* %67)
%69 = load i32*, i32** %6
%70 = call i64 @fread(i8* %66, i32 %68, i32 1, i32* %69)
store i64 %70, i64* %15
%71 = load i64, i64* %15
%72 = icmp ne i64 %71, 0
%73 = zext i1 %72 to i32
%74 = call i32 @assert(i32 %73)
%75 = load i32*, i32** %6
%76 = call i32 @fclose(i32* %75)
br label %77
77: ; preds = %22
%78 = load i32, i32* %16
%79 = add nsw i32 %78, 1
store i32 %79, i32* %16
br label %19
80: ; preds = %19
ret i32 0
}

LLVM IR (-O2):
@__const.main.c = [12 x i8] c"test string\00"
@.str = [46 x i8] c"/home/akshay/Desktop/playground/inputfile.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [47 x i8] c"/home/akshay/Desktop/playground/inputfile2.txt\00"
@.str.3 = [3 x i8] c"w+\00"
@.str.4 = [14 x i8] c"hello world 1\00"
@EOF = global i32 0
@errno = global i64 0
@.str.5 = [2 x i8] c"r\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [12 x i8]
%4 = alloca [12 x i8]
%5 = alloca [100 x i8]
%6 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [12 x i8], [12 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%9 = call i32* @fopen(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp ne i32* %9, null
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = call i32 @strlen(i8* %6)
%14 = call i32 @fwrite(i8* %6, i32 1, i32 %13, i32* %9)
%15 = icmp sgt i32 %14, 0
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = call i32 @fclose(i32* %9)
%19 = call i32* @fopen(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%20 = call i32 @fputs(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32* %19)
%21 = load i32, i32* @EOF
%22 = icmp ne i32 %20, %21
%23 = zext i1 %22 to i32
%24 = call i32 @assert(i32 %23)
%25 = call i32 @fgetc(i32* %19)
%26 = load i64, i64* @errno
%27 = icmp eq i64 %26, 0
%28 = zext i1 %27 to i32
%29 = call i32 @assert(i32 %28)
%30 = call i32 @fputc(i8 signext 120, i32* %19)
%31 = load i32, i32* @EOF
%32 = icmp ne i32 %30, %31
%33 = zext i1 %32 to i32
%34 = call i32 @assert(i32 %33)
%35 = call i32 @fclose(i32* %19)
%36 = call i32* @fopen(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%37 = call i32 @strlen(i8* %7)
%38 = call i64 @fread(i8* %8, i32 %37, i32 1, i32* %36)
%39 = icmp ne i64 %38, 0
%40 = zext i1 %39 to i32
%41 = call i32 @assert(i32 %40)
%42 = call i32 @fclose(i32* %36)
%43 = call i32* @fopen(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%44 = icmp ne i32* %43, null
%45 = zext i1 %44 to i32
%46 = call i32 @assert(i32 %45)
%47 = call i32 @strlen(i8* %6)
%48 = call i32 @fwrite(i8* %6, i32 1, i32 %47, i32* %43)
%49 = icmp sgt i32 %48, 0
%50 = zext i1 %49 to i32
%51 = call i32 @assert(i32 %50)
%52 = call i32 @fclose(i32* %43)
%53 = call i32* @fopen(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%54 = call i32 @fputs(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32* %53)
%55 = load i32, i32* @EOF
%56 = icmp ne i32 %54, %55
%57 = zext i1 %56 to i32
%58 = call i32 @assert(i32 %57)
%59 = call i32 @fgetc(i32* %53)
%60 = load i64, i64* @errno
%61 = icmp eq i64 %60, 0
%62 = zext i1 %61 to i32
%63 = call i32 @assert(i32 %62)
%64 = call i32 @fputc(i8 signext 120, i32* %53)
%65 = load i32, i32* @EOF
%66 = icmp ne i32 %64, %65
%67 = zext i1 %66 to i32
%68 = call i32 @assert(i32 %67)
%69 = call i32 @fclose(i32* %53)
%70 = call i32* @fopen(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%71 = call i32 @strlen(i8* %7)
%72 = call i64 @fread(i8* %8, i32 %71, i32 1, i32* %70)
%73 = icmp ne i64 %72, 0
%74 = zext i1 %73 to i32
%75 = call i32 @assert(i32 %74)
%76 = call i32 @fclose(i32* %70)
ret i32 0
}