#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseeek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  FILE *fp;
  fp = fopen("example.txt", "wb");
  fputs("This is an apple", fp);
  fseeek(fp, 9, SEEK_SET);
  fputs(" sam", fp);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xea3(%rip),%rdi
lea    0xea8(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe97(%rip),%rdi
call   1040 <fputs@plt>
mov    -0x18(%rbp),%rdi
mov    0x2e58(%rip),%rax
mov    (%rax),%edx
mov    $0x9,%esi
call   1050 <fseeek@plt>
mov    -0x18(%rbp),%rsi
lea    0xe81(%rip),%rdi
call   1040 <fputs@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xeb8(%rip),%rdi
lea    0xebd(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%rbx
lea    0xeb1(%rip),%rdi
mov    $0x10,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1060 <fwrite@plt>
mov    0x2e69(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x9,%esi
call   1040 <fseeek@plt>
lea    0xe93(%rip),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1060 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [12 x i8] c"example.txt\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [17 x i8] c"This is an apple\00"
@SEEK_SET = global i32 0
@.str.3 = [5 x i8] c" sam\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 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** %6
%8 = load i32*, i32** %6
%9 = call i32 @fputs(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32* %8)
%10 = load i32*, i32** %6
%11 = load i32, i32* @SEEK_SET
%12 = call i32 @fseeek(i32* %10, i32 9, i32 %11)
%13 = load i32*, i32** %6
%14 = call i32 @fputs(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32* %13)
%15 = load i32*, i32** %6
%16 = call i32 @fclose(i32* %15)
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"example.txt\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [17 x i8] c"This is an apple\00"
@SEEK_SET = global i32 0
@.str.3 = [5 x i8] c" sam\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i64 @fwrite(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i64 16, i64 1, i32* %3)
%5 = load i32, i32* @SEEK_SET
%6 = tail call i32 @fseeek(i32* %3, i32 9, i32 %5)
%7 = tail call i64 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i64 4, i64 1, i32* %3)
%8 = tail call i32 @fclose(i32* %3)
ret i32 0
}