#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 */

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int write(int, char *, long);
int saveTextToFile(char *buff, long buff_size) {
  int fdSave;
  fdSave = open("textfile.txt", O_RDONLY);
  if (!fdSave) {
    printf("*** ZVM Error. Extracted text do not save to temp file.\n");
    return 0;
  }
  int bwrite = write(fdSave, buff, buff_size);
  if (bwrite < 0) {
    printf("*** ZVM Error. Error write extracted text to file.\n");
    return 0;
  }
  close(fdSave);
  return 1;
}


x86 assembly (clang, -O0):
<saveTextToFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2e91(%rip),%rax
mov    (%rax),%esi
lea    0xea0(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    118a <saveTextToFile+0x4a>
lea    0xe94(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11ce <saveTextToFile+0x8e>
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <write@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    11bf <saveTextToFile+0x7f>
lea    0xe98(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11ce <saveTextToFile+0x8e>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<saveTextToFile>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2e97(%rip),%rax
mov    (%rax),%esi
lea    0xea6(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
je     1184 <saveTextToFile+0x44>
mov    %eax,%ebp
mov    %eax,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1040 <write@plt>
test   %eax,%eax
js     118d <saveTextToFile+0x4d>
mov    %ebp,%edi
call   1050 <close@plt>
mov    $0x1,%eax
jmp    119b <saveTextToFile+0x5b>
lea    0xe82(%rip),%rdi
jmp    1194 <saveTextToFile+0x54>
lea    0xeb1(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"textfile.txt\00"
@O_RDONLY = global i32 0
@.str.1 = [57 x i8] c"*** ZVM Error. Extracted text do not save to temp file.\0A\00"
@.str.2 = [52 x i8] c"*** ZVM Error. Error write extracted text to file.\0A\00"
define i32 @saveTextToFile(i8* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i64 %1, i64* %5
%8 = load i32, i32* @O_RDONLY
%9 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp ne i32 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %2
%13 = call i32 @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %26
14: ; preds = %2
%15 = load i32, i32* %6
%16 = load i8*, i8** %4
%17 = load i64, i64* %5
%18 = call i32 @write(i32 %15, i8* %16, i64 %17)
store i32 %18, i32* %7
%19 = load i32, i32* %7
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %14
%22 = call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %26
23: ; preds = %14
%24 = load i32, i32* %6
%25 = call i32 @close(i32 %24)
store i32 1, i32* %3
br label %26
26: ; preds = %23, %21, %12
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
@.str = [13 x i8] c"textfile.txt\00"
@O_RDONLY = global i32 0
@str = [56 x i8] c"*** ZVM Error. Extracted text do not save to temp file.\00"
@str.3 = [51 x i8] c"*** ZVM Error. Error write extracted text to file.\00"
define i32 @saveTextToFile(i8* nocapture %0, i64 %1) {
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @str, i64 0, i64 0))
br label %15
8: ; preds = %2
%9 = tail call i32 @write(i32 %4, i8* %0, i64 %1)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str.3, i64 0, i64 0))
br label %15
13: ; preds = %8
%14 = tail call i32 @close(i32 %4)
br label %15
15: ; preds = %11, %13, %6
%16 = phi i32 [ 0, %6 ], [ 0, %11 ], [ 1, %13 ]
ret i32 %16
}