#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*/ favrite_color;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
void main() {
  char favrite_color[] = "green", copied[10];
  FILE *p;
  p = fopen("test.txt", "wb+");
  fwrite(favrite_color, sizeof(favrite_color), 1, p);
  fseek(p, 0, SEEK_SET);
  fread(copied, sizeof(favrite_color), 1, p);
  printf("%s", copied);
  fclose(p);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0xe92(%rip),%eax
mov    %eax,-0x6(%rbp)
mov    0xe8c(%rip),%ax
mov    %ax,-0x2(%rbp)
lea    0xe83(%rip),%rdi
lea    0xe85(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    -0x6(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x6,%esi
mov    $0x1,%edx
call   1080 <fwrite@plt>
mov    -0x18(%rbp),%rdi
mov    0x2e2b(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <fseek@plt>
lea    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x6,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
lea    -0x10(%rbp),%rsi
lea    0xe33(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movw   $0x6e,0xc(%rsp)
movl   $0x65657267,0x8(%rsp)
65
lea    0xe89(%rip),%rdi
lea    0xe8b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
lea    0x8(%rsp),%rdi
mov    $0x6,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1080 <fwrite@plt>
mov    0x2e36(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <fseek@plt>
lea    0xe(%rsp),%r14
mov    %r14,%rdi
mov    $0x6,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
lea    0xe3c(%rip),%rdi
mov    %r14,%rsi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.favrite_color = [6 x i8] c"green\00"
@.str = [9 x i8] c"test.txt\00"
@.str.1 = [4 x i8] c"wb+\00"
@SEEK_SET = global i32 0
@.str.2 = [3 x i8] c"%s\00"
define void @main() {
%1 = alloca [6 x i8]
%2 = alloca [10 x i8]
%3 = alloca i32*
%4 = bitcast [6 x i8]* %1 to i8*
%5 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %3
%6 = getelementptr inbounds [6 x i8], [6 x i8]* %1, i64 0, i64 0
%7 = load i32*, i32** %3
%8 = call i32 @fwrite(i8* %6, i32 6, i32 1, i32* %7)
%9 = load i32*, i32** %3
%10 = load i32, i32* @SEEK_SET
%11 = call i32 @fseek(i32* %9, i32 0, i32 %10)
%12 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%13 = load i32*, i32** %3
%14 = call i32 @fread(i8* %12, i32 6, i32 1, i32* %13)
%15 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%16 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%17 = load i32*, i32** %3
%18 = call i32 @fclose(i32* %17)
ret void
}

LLVM IR (-O2):
@__const.main.favrite_color = [6 x i8] c"green\00"
@.str = [9 x i8] c"test.txt\00"
@.str.1 = [4 x i8] c"wb+\00"
@SEEK_SET = global i32 0
@.str.2 = [3 x i8] c"%s\00"
define void @main() {
%1 = alloca [6 x i8]
%2 = alloca [10 x i8]
%3 = getelementptr inbounds [6 x i8], [6 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [10 x i8], [10 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 ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 @fwrite(i8* %3, i32 6, i32 1, i32* %5)
%7 = load i32, i32* @SEEK_SET
%8 = tail call i32 @fseek(i32* %5, i32 0, i32 %7)
%9 = call i32 @fread(i8* %4, i32 6, i32 1, i32* %5)
%10 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%11 = call i32 @fclose(i32* %5)
ret void
}