#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_SET;
int /*<<< orphan*/ assert(int);
int errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(char *, scalar_t__, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int /*<<< orphan*/ fwrite(char *, scalar_t__, int, int /*<<< orphan*/ *);
scalar_t__ strlen(char *);
int main() {
  FILE *fp;
  char c[] = "test string";
  char buffer[100];
  size_t err;
  fp = fopen("file.txt", "w+");
  fwrite(c, strlen(c) + 1, 1, fp);
  fseek(fp, 0, SEEK_SET);
  err = fread(buffer, strlen(c) + 1, 1, fp);
  assert(err == 0);
  fclose(fp);
  return errno;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe77(%rip),%rax
mov    %rax,-0x1c(%rbp)
mov    0xe75(%rip),%eax
mov    %eax,-0x14(%rbp)
lea    0xe6f(%rip),%rdi
lea    0xe71(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    -0x1c(%rbp),%rax
mov    %rax,-0x98(%rbp)
lea    -0x1c(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x98(%rbp),%rdi
mov    %rax,%rsi
add    $0x1,%rsi
mov    -0x10(%rbp),%rcx
mov    $0x1,%edx
call   1090 <fwrite@plt>
mov    -0x10(%rbp),%rdi
mov    0x2df0(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <fseek@plt>
lea    -0x80(%rbp),%rax
mov    %rax,-0x90(%rbp)
lea    -0x1c(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x90(%rbp),%rdi
mov    %rax,%rsi
add    $0x1,%rsi
mov    -0x10(%rbp),%rcx
mov    $0x1,%edx
call   1030 <fread@plt>
mov    %rax,-0x88(%rbp)
cmpq   $0x0,-0x88(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2d93(%rip),%rax
mov    (%rax),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x78,%rsp
movabs $0x7274732074736574,%rax
73 74 72
mov    %rax,(%rsp)
movl   $0x676e69,0x8(%rsp)
lea    0xe78(%rip),%rdi
lea    0xe7a(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
mov    %rsp,%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rsi
mov    %r14,%rdi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1090 <fwrite@plt>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <fseek@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rsi
lea    0x10(%rsp),%rdi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1060 <assert@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0x2dd0(%rip),%rax
mov    (%rax),%eax
add    $0x78,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.c = [12 x i8] c"test string\00"
@.str = [9 x i8] c"file.txt\00"
@.str.1 = [3 x i8] c"w+\00"
@SEEK_SET = global i32 0
@errno = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [12 x i8]
%4 = alloca [100 x i8]
%5 = alloca i64
store i32 0, i32* %1
%6 = bitcast [12 x i8]* %3 to i8*
%7 = 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* %7, i32** %2
%8 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%10 = call i64 @strlen(i8* %9)
%11 = add nsw i64 %10, 1
%12 = load i32*, i32** %2
%13 = call i32 @fwrite(i8* %8, i64 %11, i32 1, i32* %12)
%14 = load i32*, i32** %2
%15 = load i32, i32* @SEEK_SET
%16 = call i32 @fseek(i32* %14, i32 0, i32 %15)
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%18 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%19 = call i64 @strlen(i8* %18)
%20 = add nsw i64 %19, 1
%21 = load i32*, i32** %2
%22 = call i64 @fread(i8* %17, i64 %20, i32 1, i32* %21)
store i64 %22, i64* %5
%23 = load i64, i64* %5
%24 = icmp eq i64 %23, 0
%25 = zext i1 %24 to i32
%26 = call i32 @assert(i32 %25)
%27 = load i32*, i32** %2
%28 = call i32 @fclose(i32* %27)
%29 = load i32, i32* @errno
ret i32 %29
}

LLVM IR (-O2):
@__const.main.c = [12 x i8] c"test string\00"
@.str = [9 x i8] c"file.txt\00"
@.str.1 = [3 x i8] c"w+\00"
@SEEK_SET = global i32 0
@errno = global i32 0
define i32 @main() {
%1 = alloca [12 x i8]
%2 = alloca [100 x i8]
%3 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%5 = 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))
%6 = call i64 @strlen(i8* %3)
%7 = add nsw i64 %6, 1
%8 = call i32 @fwrite(i8* %3, i64 %7, i32 1, i32* %5)
%9 = load i32, i32* @SEEK_SET
%10 = tail call i32 @fseek(i32* %5, i32 0, i32 %9)
%11 = call i64 @strlen(i8* %3)
%12 = add nsw i64 %11, 1
%13 = call i64 @fread(i8* %4, i64 %12, i32 1, i32* %5)
%14 = icmp eq i64 %13, 0
%15 = zext i1 %14 to i32
%16 = tail call i32 @assert(i32 %15)
%17 = tail call i32 @fclose(i32* %5)
%18 = load i32, i32* @errno
ret i32 %18
}