#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*/ asprintf(char **, char *, ...);
int /*<<< orphan*/ copy_and_return_nonemptiness(int);
int /*<<< orphan*/ gui_fatal(char *);
int /*<<< orphan*/ gui_nonfatal(char *);
int mkstemp(char *);
int /*<<< orphan*/ unlink(char *);
void recv_file_nowrite(char *fname) {
  char *tempfile;
  char *errmsg;
  int tmpfd;
  asprintf(&tempfile, "/tmp/file_edited_in_dvm.XXXXXX");
  tmpfd = mkstemp(tempfile);
  if (tmpfd < 0)
    gui_fatal("unable to create any temporary file, aborting");
  if (!copy_and_return_nonemptiness(tmpfd)) {
    unlink(tempfile);
    return;
  }
  asprintf(&errmsg,
           "The file %s has been edited in Disposable VM and the modified "
           "content has been received, "
           "but this file is in nonwritable directory and thus cannot be "
           "modified safely. The edited file has been "
           "saved to %s",
           fname, tempfile);
  gui_nonfatal(errmsg);
}


x86 assembly (clang, -O0):
<recv_file_nowrite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x10(%rbp),%rdi
lea    0xe89(%rip),%rsi
mov    $0x0,%al
call   1070 <asprintf@plt>
mov    -0x10(%rbp),%rdi
call   1060 <mkstemp@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11a0 <recv_file_nowrite+0x40>
lea    0xe84(%rip),%rdi
call   1080 <gui_fatal@plt>
mov    -0x1c(%rbp),%edi
call   1050 <copy_and_return_nonemptiness@plt>
cmp    $0x0,%eax
jne    11bf <recv_file_nowrite+0x5f>
mov    -0x10(%rbp),%rdi
call   1030 <unlink@plt>
jmp    11e2 <recv_file_nowrite+0x82>
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    -0x18(%rbp),%rdi
lea    0xe7b(%rip),%rsi
mov    $0x0,%al
call   1070 <asprintf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <gui_nonfatal@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recv_file_nowrite>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
lea    0xe90(%rip),%rsi
lea    0x8(%rsp),%rdi
xor    %eax,%eax
call   1070 <asprintf@plt>
mov    0x8(%rsp),%rdi
call   1060 <mkstemp@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1198 <recv_file_nowrite+0x38>
lea    0xe8c(%rip),%rdi
call   1080 <gui_fatal@plt>
mov    %ebp,%edi
call   1050 <copy_and_return_nonemptiness@plt>
mov    0x8(%rsp),%rcx
test   %eax,%eax
je     11ca <recv_file_nowrite+0x6a>
lea    0xe9e(%rip),%rsi
lea    0x10(%rsp),%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <asprintf@plt>
mov    0x10(%rsp),%rdi
call   1040 <gui_nonfatal@plt>
jmp    11d2 <recv_file_nowrite+0x72>
mov    %rcx,%rdi
call   1030 <unlink@plt>
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [31 x i8] c"/tmp/file_edited_in_dvm.XXXXXX\00"
@.str.1 = [46 x i8] c"unable to create any temporary file, aborting\00"
@.str.2 = [204 x i8] c"The file %s has been edited in Disposable VM and the modified content has been received, but this file is in nonwritable directory and thus cannot be modified safely. The edited file has been saved to %s\00"
define void @recv_file_nowrite(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %2
%6 = call i32 (i8**, i8*, ...) @asprintf(i8** %3, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%7 = load i8*, i8** %3
%8 = call i32 @mkstemp(i8* %7)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = call i32 @gui_fatal(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %11, %1
%14 = load i32, i32* %5
%15 = call i32 @copy_and_return_nonemptiness(i32 %14)
%16 = icmp ne i32 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %13
%18 = load i8*, i8** %3
%19 = call i32 @unlink(i8* %18)
br label %26
20: ; preds = %13
%21 = load i8*, i8** %2
%22 = load i8*, i8** %3
%23 = call i32 (i8**, i8*, ...) @asprintf(i8** %4, i8* getelementptr inbounds ([204 x i8], [204 x i8]* @.str.2, i64 0, i64 0), i8* %21, i8* %22)
%24 = load i8*, i8** %4
%25 = call i32 @gui_nonfatal(i8* %24)
br label %26
26: ; preds = %20, %17
ret void
}

LLVM IR (-O2):
@.str = [31 x i8] c"/tmp/file_edited_in_dvm.XXXXXX\00"
@.str.1 = [46 x i8] c"unable to create any temporary file, aborting\00"
@.str.2 = [204 x i8] c"The file %s has been edited in Disposable VM and the modified content has been received, but this file is in nonwritable directory and thus cannot be modified safely. The edited file has been saved to %s\00"
define void @recv_file_nowrite(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = bitcast i8** %2 to i8*
%5 = bitcast i8** %3 to i8*
%6 = call i32 (i8**, i8*, ...) @asprintf(i8** %2, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%7 = load i8*, i8** %2
%8 = call i32 @mkstemp(i8* %7)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i32 @gui_fatal(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %1
%13 = call i32 @copy_and_return_nonemptiness(i32 %8)
%14 = icmp eq i32 %13, 0
%15 = load i8*, i8** %2
br i1 %14, label %16, label %18
16: ; preds = %12
%17 = call i32 @unlink(i8* %15)
br label %22
18: ; preds = %12
%19 = call i32 (i8**, i8*, ...) @asprintf(i8** %3, i8* getelementptr inbounds ([204 x i8], [204 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %15)
%20 = load i8*, i8** %3
%21 = call i32 @gui_nonfatal(i8* %20)
br label %22
22: ; preds = %18, %16
ret void
}