#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*/ close_file(int /*<<< orphan*/ **);
int /*<<< orphan*/ *fopen(int /*<<< orphan*/, char *);
scalar_t__ fputs(char *, int /*<<< orphan*/ *);
scalar_t__ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
long get_num(char *, char *);
int /*<<< orphan*/ get_string(char *);
char *s_let(char *, char *);
char *macwritetofile(char *arg) {
  FILE *file = NULL;
  char str[10240];
  long pos;
  get_string(str);
  pos = get_num("writetofile", arg);
  if ((file = fopen(get_string(arg), "r+")) == NULL)
    return (s_let("false", arg));
  if (fseek(file, pos, SEEK_SET)) {
    close_file(&file);
    return (s_let("false", arg));
  }
  if (fputs(str, file) < 0)
    s_let("false", arg);
  else
    s_let("true", arg);
  close_file(&file);
  return (arg);
}


x86 assembly (clang, -O0):
<macwritetofile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2830,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
lea    -0x2820(%rbp),%rdi
call   1060 <get_string@plt>
mov    -0x10(%rbp),%rsi
lea    0xe62(%rip),%rdi
call   1040 <get_num@plt>
mov    %rax,-0x2828(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <get_string@plt>
mov    %eax,%edi
lea    0xe50(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11e8 <macwritetofile+0x78>
mov    -0x10(%rbp),%rsi
lea    0xe35(%rip),%rdi
call   1050 <s_let@plt>
mov    %rax,-0x8(%rbp)
jmp    127d <macwritetofile+0x10d>
mov    -0x18(%rbp),%rdi
mov    -0x2828(%rbp),%rsi
mov    0x2de6(%rip),%rax
mov    (%rax),%edx
call   1080 <fseek@plt>
cmp    $0x0,%rax
je     122d <macwritetofile+0xbd>
lea    -0x18(%rbp),%rdi
call   1030 <close_file@plt>
mov    -0x10(%rbp),%rsi
lea    0xdf0(%rip),%rdi
call   1050 <s_let@plt>
mov    %rax,-0x8(%rbp)
jmp    127d <macwritetofile+0x10d>
lea    -0x2820(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <fputs@plt>
cmp    $0x0,%rax
jge    125c <macwritetofile+0xec>
mov    -0x10(%rbp),%rsi
lea    0xdbd(%rip),%rdi
call   1050 <s_let@plt>
jmp    126c <macwritetofile+0xfc>
mov    -0x10(%rbp),%rsi
lea    0xdae(%rip),%rdi
call   1050 <s_let@plt>
lea    -0x18(%rbp),%rdi
call   1030 <close_file@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x2830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<macwritetofile>:
push   %r14
push   %rbx
sub    $0x2818,%rsp
mov    %rdi,%rbx
lea    0x10(%rsp),%rdi
call   1060 <get_string@plt>
lea    0xe72(%rip),%rdi
mov    %rbx,%rsi
call   1040 <get_num@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1060 <get_string@plt>
lea    0xe64(%rip),%rsi
mov    %eax,%edi
call   1090 <fopen@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
je     11dc <macwritetofile+0x6c>
mov    0x2e20(%rip),%rcx
mov    (%rcx),%edx
mov    %rax,%rdi
mov    %r14,%rsi
call   1080 <fseek@plt>
test   %rax,%rax
je     11f0 <macwritetofile+0x80>
lea    0x8(%rsp),%rdi
call   1030 <close_file@plt>
lea    0xe2c(%rip),%rdi
mov    %rbx,%rsi
call   1050 <s_let@plt>
mov    %rax,%rbx
jmp    1226 <macwritetofile+0xb6>
mov    0x8(%rsp),%rsi
lea    0x10(%rsp),%rdi
call   1070 <fputs@plt>
test   %rax,%rax
lea    0xe06(%rip),%rax
lea    0xe05(%rip),%rdi
cmovs  %rax,%rdi
mov    %rbx,%rsi
call   1050 <s_let@plt>
lea    0x8(%rsp),%rdi
call   1030 <close_file@plt>
mov    %rbx,%rax
add    $0x2818,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [12 x i8] c"writetofile\00"
@.str.1 = [3 x i8] c"r+\00"
@.str.2 = [6 x i8] c"false\00"
@SEEK_SET = global i32 0
@.str.3 = [5 x i8] c"true\00"
define i8* @macwritetofile(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [10240 x i8]
%6 = alloca i64
store i8* %0, i8** %3
store i32* null, i32** %4
%7 = getelementptr inbounds [10240 x i8], [10240 x i8]* %5, i64 0, i64 0
%8 = call i32 @get_string(i8* %7)
%9 = load i8*, i8** %3
%10 = call i64 @get_num(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %9)
store i64 %10, i64* %6
%11 = load i8*, i8** %3
%12 = call i32 @get_string(i8* %11)
%13 = call i32* @fopen(i32 %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %13, i32** %4
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %1
%16 = load i8*, i8** %3
%17 = call i8* @s_let(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %16)
store i8* %17, i8** %2
br label %42
18: ; preds = %1
%19 = load i32*, i32** %4
%20 = load i64, i64* %6
%21 = load i32, i32* @SEEK_SET
%22 = call i64 @fseek(i32* %19, i64 %20, i32 %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %18
%25 = call i32 @close_file(i32** %4)
%26 = load i8*, i8** %3
%27 = call i8* @s_let(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %26)
store i8* %27, i8** %2
br label %42
28: ; preds = %18
%29 = getelementptr inbounds [10240 x i8], [10240 x i8]* %5, i64 0, i64 0
%30 = load i32*, i32** %4
%31 = call i64 @fputs(i8* %29, i32* %30)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %28
%34 = load i8*, i8** %3
%35 = call i8* @s_let(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %34)
br label %39
36: ; preds = %28
%37 = load i8*, i8** %3
%38 = call i8* @s_let(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %37)
br label %39
39: ; preds = %36, %33
%40 = call i32 @close_file(i32** %4)
%41 = load i8*, i8** %3
store i8* %41, i8** %2
br label %42
42: ; preds = %39, %24, %15
%43 = load i8*, i8** %2
ret i8* %43
}

LLVM IR (-O2):
@.str = [12 x i8] c"writetofile\00"
@.str.1 = [3 x i8] c"r+\00"
@.str.2 = [6 x i8] c"false\00"
@SEEK_SET = global i32 0
@.str.3 = [5 x i8] c"true\00"
define i8* @macwritetofile(i8* %0) {
%2 = alloca i32*
%3 = alloca [10240 x i8]
%4 = bitcast i32** %2 to i8*
%5 = getelementptr inbounds [10240 x i8], [10240 x i8]* %3, i64 0, i64 0
%6 = call i32 @get_string(i8* %5)
%7 = call i64 @get_num(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %0)
%8 = call i32 @get_string(i8* %0)
%9 = call i32* @fopen(i32 %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %2
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = call i8* @s_let(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %27
13: ; preds = %1
%14 = load i32, i32* @SEEK_SET
%15 = call i64 @fseek(i32* %9, i64 %7, i32 %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %13
%18 = call i32 @close_file(i32** %2)
%19 = call i8* @s_let(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %27
20: ; preds = %13
%21 = load i32*, i32** %2
%22 = call i64 @fputs(i8* %5, i32* %21)
%23 = icmp slt i64 %22, 0
%24 = select i1 %23, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0)
%25 = call i8* @s_let(i8* %24, i8* %0)
%26 = call i32 @close_file(i32** %2)
br label %27
27: ; preds = %20, %17, %11
%28 = phi i8* [ %12, %11 ], [ %19, %17 ], [ %0, %20 ]
ret i8* %28
}