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

/* Variables and functions */
int errno;
int /*<<< orphan*/ execl(char const *, char const *, char *, char *, char *,
                         char const *, char *, int /*<<< orphan*/ *);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, ...);
char *getenv(char *);
scalar_t__ getpid();
int /*<<< orphan*/ ignore_children();
int /*<<< orphan*/ rye(int);
int /*<<< orphan*/ simplify_env();
int /*<<< orphan*/ unsetenv(char *);
void launch_vis(const char *filename, FILE *log) {
  const char *pv = getenv("PVBATCH");
  if (pv == NULL) {
    pv = "/usr/bin/pvbatch";
  }
  fprintf(log, "[%d] using '%s' for pvbatch\n", (int)getpid(), pv);
  unsetenv("LD_PRELOAD");
  if (getenv("LIBSITU_SYNC") == NULL) {
    ignore_children();
  }
  pid_t pid = fork();
  if (pid == -1) {
    fprintf(log, "Could not fork vis process: %d\n", errno);
    return;
  }
  if (pid == 0) {
    simplify_env();
    execl(pv, pv, "--use-offscreen-rendering", "batch.py", "-f", filename, "-g",
          NULL);
    fprintf(log, "could not exec pvbatch: %d\n", errno);
    return;
  }
  rye(pid);
}


x86 assembly (clang, -O0):
<launch_vis>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe59(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c6 <launch_vis+0x36>
lea    0xe46(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1060 <getpid@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%edx
mov    -0x18(%rbp),%rcx
lea    0xe33(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
lea    0xe42(%rip),%rdi
call   1090 <unsetenv@plt>
lea    0xe41(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
jne    1216 <launch_vis+0x86>
mov    $0x0,%al
call   1040 <ignore_children@plt>
mov    $0x0,%al
call   10b0 <fork@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    124a <launch_vis+0xba>
mov    -0x10(%rbp),%rdi
mov    0x2dab(%rip),%rax
mov    (%rax),%edx
lea    0xe10(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    12c0 <launch_vis+0x130>
cmpl   $0x0,-0x1c(%rbp)
jne    12b8 <launch_vis+0x128>
mov    $0x0,%al
call   1050 <simplify_env@plt>
mov    -0x18(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x8(%rbp),%r9
lea    0xe00(%rip),%rdx
lea    0xe13(%rip),%rcx
lea    0xe15(%rip),%r8
lea    0xe11(%rip),%rax
xor    %r10d,%r10d
mov    %rax,(%rsp)
movq   $0x0,0x8(%rsp)
call   10a0 <execl@plt>
mov    -0x10(%rbp),%rdi
mov    0x2d3d(%rip),%rax
mov    (%rax),%edx
lea    0xdeb(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    12c0 <launch_vis+0x130>
mov    -0x1c(%rbp),%edi
call   1070 <rye@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<launch_vis>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
lea    0xe5e(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
lea    0xe57(%rip),%rbx
cmovne %rax,%rbx
xor    %eax,%eax
call   1060 <getpid@plt>
lea    0xe56(%rip),%rsi
mov    %r15,%rdi
mov    %eax,%edx
mov    %rbx,%rcx
xor    %eax,%eax
call   1080 <fprintf@plt>
lea    0xe5d(%rip),%rdi
call   1090 <unsetenv@plt>
lea    0xe5c(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
jne    11f6 <launch_vis+0x66>
xor    %eax,%eax
call   1040 <ignore_children@plt>
xor    %eax,%eax
call   10b0 <fork@plt>
test   %eax,%eax
je     1218 <launch_vis+0x88>
cmp    $0xffffffff,%eax
jne    126f <launch_vis+0xdf>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edx
lea    0xe38(%rip),%rsi
jmp    1260 <launch_vis+0xd0>
xor    %eax,%eax
call   1050 <simplify_env@plt>
lea    0xe6e(%rip),%rax
lea    0xe41(%rip),%rdx
lea    0xe54(%rip),%rcx
lea    0xe56(%rip),%r8
mov    %rbx,%rdi
mov    %rbx,%rsi
mov    %r14,%r9
push   $0x0
push   %rax
call   10a0 <execl@plt>
add    $0x10,%rsp
mov    0x2d89(%rip),%rax
mov    (%rax),%edx
lea    0xe37(%rip),%rsi
mov    %r15,%rdi
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
jmp    1080 <fprintf@plt>
mov    %eax,%edi
pop    %rbx
pop    %r14
pop    %r15
jmp    1070 <rye@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"PVBATCH\00"
@.str.1 = [17 x i8] c"/usr/bin/pvbatch\00"
@.str.2 = [29 x i8] c"[%d] using '%s' for pvbatch\0A\00"
@.str.3 = [11 x i8] c"LD_PRELOAD\00"
@.str.4 = [13 x i8] c"LIBSITU_SYNC\00"
@.str.5 = [32 x i8] c"Could not fork vis process: %d\0A\00"
@errno = global i32 0
@.str.6 = [26 x i8] c"--use-offscreen-rendering\00"
@.str.7 = [9 x i8] c"batch.py\00"
@.str.8 = [3 x i8] c"-f\00"
@.str.9 = [3 x i8] c"-g\00"
@.str.10 = [28 x i8] c"could not exec pvbatch: %d\0A\00"
define void @launch_vis(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
store i32* %1, i32** %4
%7 = call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i8* %7, i8** %5
%8 = load i8*, i8** %5
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %11
10: ; preds = %2
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8** %5
br label %11
11: ; preds = %10, %2
%12 = load i32*, i32** %4
%13 = call i64 (...) @getpid()
%14 = trunc i64 %13 to i32
%15 = load i8*, i8** %5
%16 = call i32 (i32*, i8*, i32, ...) @fprintf(i32* %12, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %14, i8* %15)
%17 = call i32 @unsetenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%18 = call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %22
20: ; preds = %11
%21 = call i32 (...) @ignore_children()
br label %22
22: ; preds = %20, %11
%23 = call i32 (...) @fork()
store i32 %23, i32* %6
%24 = load i32, i32* %6
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %30
26: ; preds = %22
%27 = load i32*, i32** %4
%28 = load i32, i32* @errno
%29 = call i32 (i32*, i8*, i32, ...) @fprintf(i32* %27, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i32 %28)
br label %45
30: ; preds = %22
%31 = load i32, i32* %6
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %42
33: ; preds = %30
%34 = call i32 (...) @simplify_env()
%35 = load i8*, i8** %5
%36 = load i8*, i8** %5
%37 = load i8*, i8** %3
%38 = call i32 @execl(i8* %35, i8* %36, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i32* null)
%39 = load i32*, i32** %4
%40 = load i32, i32* @errno
%41 = call i32 (i32*, i8*, i32, ...) @fprintf(i32* %39, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.10, i64 0, i64 0), i32 %40)
br label %45
42: ; preds = %30
%43 = load i32, i32* %6
%44 = call i32 @rye(i32 %43)
br label %45
45: ; preds = %42, %33, %26
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"PVBATCH\00"
@.str.1 = [17 x i8] c"/usr/bin/pvbatch\00"
@.str.2 = [29 x i8] c"[%d] using '%s' for pvbatch\0A\00"
@.str.3 = [11 x i8] c"LD_PRELOAD\00"
@.str.4 = [13 x i8] c"LIBSITU_SYNC\00"
@.str.5 = [32 x i8] c"Could not fork vis process: %d\0A\00"
@errno = global i32 0
@.str.6 = [26 x i8] c"--use-offscreen-rendering\00"
@.str.7 = [9 x i8] c"batch.py\00"
@.str.8 = [3 x i8] c"-f\00"
@.str.9 = [3 x i8] c"-g\00"
@.str.10 = [28 x i8] c"could not exec pvbatch: %d\0A\00"
define void @launch_vis(i8* %0, i32* nocapture %1) {
%3 = tail call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8* %3, null
%5 = select i1 %4, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %3
%6 = tail call i64 (...) @getpid()
%7 = trunc i64 %6 to i32
%8 = tail call i32 (i32*, i8*, i32, ...) @fprintf(i32* %1, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %7, i8* %5)
%9 = tail call i32 @unsetenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%10 = tail call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = tail call i32 (...) @ignore_children()
br label %14
14: ; preds = %12, %2
%15 = tail call i32 (...) @fork()
switch i32 %15, label %24 [
i32 -1, label %16
i32 0, label %19
]
16: ; preds = %14
%17 = load i32, i32* @errno
%18 = tail call i32 (i32*, i8*, i32, ...) @fprintf(i32* %1, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i32 %17)
br label %26
19: ; preds = %14
%20 = tail call i32 (...) @simplify_env()
%21 = tail call i32 @execl(i8* %5, i8* %5, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i32* null)
%22 = load i32, i32* @errno
%23 = tail call i32 (i32*, i8*, i32, ...) @fprintf(i32* %1, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.10, i64 0, i64 0), i32 %22)
br label %26
24: ; preds = %14
%25 = tail call i32 @rye(i32 %15)
br label %26
26: ; preds = %24, %19, %16
ret void
}