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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe8a(%rip),%rax
mov    %rax,-0x1c(%rbp)
mov    0xe88(%rip),%eax
mov    %eax,-0x14(%rbp)
lea    0xe82(%rip),%rdi
lea    0xe84(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    -0x1c(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    -0x1c(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    %rax,%rsi
add    $0x1,%rsi
mov    -0x10(%rbp),%rcx
mov    $0x1,%edx
call   1080 <fwrite@plt>
mov    -0x10(%rbp),%rdi
mov    0x2e09(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <fseek@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0xffffffffffffffff,-0x28(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rdi
mov    0x2ddf(%rip),%rax
mov    (%rax),%edx
mov    $0x5,%esi
call   1060 <fseek@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0xffffffffffffffff,-0x28(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2db5(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movabs $0x7274732074736574,%rax
73 74 72
mov    %rax,0x8(%rsp)
movl   $0x676e69,0x10(%rsp)
lea    0xe87(%rip),%rdi
lea    0xe89(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
lea    0x8(%rsp),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rsi
mov    %r14,%rdi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1080 <fwrite@plt>
mov    0x2e1c(%rip),%r14
mov    (%r14),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <fseek@plt>
xor    %edi,%edi
cmp    $0xffffffffffffffff,%rax
sete   %dil
call   1050 <assert@plt>
mov    (%r14),%edx
mov    %rbx,%rdi
mov    $0x5,%esi
call   1060 <fseek@plt>
xor    %edi,%edi
cmp    $0xffffffffffffffff,%rax
sete   %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0x2dda(%rip),%rax
mov    (%rax),%eax
add    $0x18,%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 i64
store i32 0, i32* %1
%5 = bitcast [12 x i8]* %3 to i8*
%6 = 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* %6, i32** %2
%7 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%9 = call i64 @strlen(i8* %8)
%10 = add nsw i64 %9, 1
%11 = load i32*, i32** %2
%12 = call i32 @fwrite(i8* %7, i64 %10, i32 1, i32* %11)
%13 = load i32*, i32** %2
%14 = load i32, i32* @SEEK_SET
%15 = call i64 @fseek(i32* %13, i32 0, i32 %14)
store i64 %15, i64* %4
%16 = load i64, i64* %4
%17 = icmp eq i64 %16, -1
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = load i32*, i32** %2
%21 = load i32, i32* @SEEK_SET
%22 = call i64 @fseek(i32* %20, i32 5, i32 %21)
store i64 %22, i64* %4
%23 = load i64, i64* %4
%24 = icmp eq i64 %23, -1
%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 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 0
%3 = 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))
%4 = call i64 @strlen(i8* %2)
%5 = add nsw i64 %4, 1
%6 = call i32 @fwrite(i8* %2, i64 %5, i32 1, i32* %3)
%7 = load i32, i32* @SEEK_SET
%8 = tail call i64 @fseek(i32* %3, i32 0, i32 %7)
%9 = icmp eq i64 %8, -1
%10 = zext i1 %9 to i32
%11 = tail call i32 @assert(i32 %10)
%12 = load i32, i32* @SEEK_SET
%13 = tail call i64 @fseek(i32* %3, i32 5, i32 %12)
%14 = icmp eq i64 %13, -1
%15 = zext i1 %14 to i32
%16 = tail call i32 @assert(i32 %15)
%17 = tail call i32 @fclose(i32* %3)
%18 = load i32, i32* @errno
ret i32 %18
}