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

/* Variables and functions */
scalar_t__ EINTR;
int /*<<< orphan*/ STDOUT_FILENO;
int WEXITSTATUS(int);
int /*<<< orphan*/ WIFEXITED(int);
int /*<<< orphan*/ chdir(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dlg_log_error(char *);
int /*<<< orphan*/ dlg_log_printf(char *, ...);
scalar_t__ dup2(int, int /*<<< orphan*/);
scalar_t__ errno;
int /*<<< orphan*/ execlp(char const *, char const *, char const *,
                          char const *, char *);
int /*<<< orphan*/ exit(int);
scalar_t__ fflush(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
char *getenv(char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
scalar_t__ pipe(int *);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
size_t strcspn(char *, char *);
char *strdup(char *);
int /*<<< orphan*/ strerror(scalar_t__);
int /*<<< orphan*/ umask(int /*<<< orphan*/);
scalar_t__ waitpid(scalar_t__, int *, int /*<<< orphan*/);
char *sdialog_call_modal(const char *path, const char *msg,
                         const char *pinName) {
  pid_t pid;
  size_t len;
  char *response;
  int p[2], status, ret;
  char buf[1024];
  dlg_log_printf("... fflush\n");
  if (fflush(stdout) != 0) {
    dlg_log_error("sdialog_call_modal/fflush");
    return NULL;
  }
  dlg_log_printf("... pipe\n");
  if (pipe(p) < 0) {
    dlg_log_error("sdialog_call_modal/pipe");
    return NULL;
  }
  dlg_log_printf("... fork\n");
  if ((pid = fork()) < 0) {
    dlg_log_error("sdialog_call_modal/fork");
    return NULL;
  }
  if (pid == 0) {
    char *disp = getenv("DISPLAY");
    fprintf(stderr, "sdialog_call_modal: in child\n");
    if (disp != NULL) {
      fprintf(stderr, "sdialog_call_modal: DISPLAY=%s\n", disp);
    } else {
      fprintf(stderr, "DISPLAY not set\n");
    }
    umask(0);
    chdir("/");
    close(p[0]);
    if (dup2(p[1], STDOUT_FILENO) < 0) {
      fprintf(stderr, "sdialog_call_modal/child/dup2");
      exit(1);
    }
    fprintf(stderr, "call_dialog_result: about to exec %s\n", path);
    execlp(path, path, pinName, msg, (char *)0);
    fprintf(stderr, "sdialog_call_modal/execlp");
    exit(1);
  }
  dlg_log_printf("sdialog_call_modal: child PID=%d\n", pid);
  dlg_log_printf("sdialog_call_modal: reading result\n");
  close(p[1]);
  len = ret = 0;
  do {
    ret = read(p[0], buf + len, sizeof(buf) - 1 - len);
    if (ret == -1 && errno == EINTR)
      continue;
    if (ret <= 0)
      break;
    len += ret;
  } while (sizeof(buf) - 1 - len > 0);
  buf[len] = '\0';
  close(p[0]);
  dlg_log_printf("sdialog_call_modal: waiting for child to die\n");
  while (waitpid(pid, &status, 0) < 0) {
    if (errno != EINTR) {
      dlg_log_printf("sdialog_call_modal: waitpid returned with error %s",
                     strerror(errno));
      break;
    }
  }
  if (!WIFEXITED(status) || WEXITSTATUS(status) > 1) {
    dlg_log_printf("sdialog_call_modal: child died badly: if %d, st %d\n",
                   WIFEXITED(status), WEXITSTATUS(status));
    memset(buf, 0, sizeof(buf));
    return NULL;
  }
  dlg_log_printf("sdialog_call_modal: child died normally\n");
  buf[strcspn(buf, "\r\n")] = '\0';
  response = strdup(buf);
  memset(buf, 0, sizeof(buf));
  return response;
}


x86 assembly (clang, -O0):
<sdialog_call_modal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
lea    0xd92(%rip),%rdi
mov    $0x0,%al
call   1110 <dlg_log_printf@plt>
mov    0x2d44(%rip),%rax
mov    (%rax),%edi
call   10e0 <fflush@plt>
cmp    $0x0,%rax
je     12a6 <sdialog_call_modal+0x56>
lea    0xd78(%rip),%rdi
call   1090 <dlg_log_error@plt>
movq   $0x0,-0x8(%rbp)
jmp    1635 <sdialog_call_modal+0x3e5>
lea    0xd79(%rip),%rdi
mov    $0x0,%al
call   1110 <dlg_log_printf@plt>
lea    -0x40(%rbp),%rdi
call   1080 <pipe@plt>
cmp    $0x0,%rax
jge    12e0 <sdialog_call_modal+0x90>
lea    0xd62(%rip),%rdi
call   1090 <dlg_log_error@plt>
movq   $0x0,-0x8(%rbp)
jmp    1635 <sdialog_call_modal+0x3e5>
lea    0xd61(%rip),%rdi
mov    $0x0,%al
call   1110 <dlg_log_printf@plt>
mov    $0x0,%al
call   1170 <fork@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jge    131c <sdialog_call_modal+0xcc>
lea    0xd48(%rip),%rdi
call   1090 <dlg_log_error@plt>
movq   $0x0,-0x8(%rbp)
jmp    1635 <sdialog_call_modal+0x3e5>
cmpq   $0x0,-0x28(%rbp)
jne    1446 <sdialog_call_modal+0x1f6>
lea    0xd3c(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x458(%rbp)
mov    0x2c97(%rip),%rax
mov    (%rax),%edi
lea    0xd28(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
cmpq   $0x0,-0x458(%rbp)
je     1382 <sdialog_call_modal+0x132>
mov    0x2c72(%rip),%rax
mov    (%rax),%edi
mov    -0x458(%rbp),%rdx
lea    0xd1a(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
jmp    1399 <sdialog_call_modal+0x149>
mov    0x2c4f(%rip),%rax
mov    (%rax),%edi
lea    0xd1e(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
xor    %edi,%edi
call   10d0 <umask@plt>
lea    0xd1a(%rip),%rdi
call   1040 <chdir@plt>
mov    -0x40(%rbp),%edi
call   1070 <close@plt>
mov    -0x3c(%rbp),%edi
mov    0x2c32(%rip),%rax
mov    (%rax),%esi
call   1050 <dup2@plt>
cmp    $0x0,%rax
jge    13f0 <sdialog_call_modal+0x1a0>
mov    0x2c02(%rip),%rax
mov    (%rax),%edi
lea    0xce4(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    0x2be1(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xcdd(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1150 <execlp@plt>
mov    0x2bac(%rip),%rax
mov    (%rax),%edi
lea    0xcd2(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    -0x28(%rbp),%rsi
lea    0xcd0(%rip),%rdi
mov    $0x0,%al
call   1110 <dlg_log_printf@plt>
lea    0xce4(%rip),%rdi
mov    $0x0,%al
call   1110 <dlg_log_printf@plt>
mov    -0x3c(%rbp),%edi
call   1070 <close@plt>
movl   $0x0,-0x48(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x40(%rbp),%edi
lea    -0x450(%rbp),%rsi
add    -0x30(%rbp),%rsi
mov    $0x3ff,%eax
sub    -0x30(%rbp),%rax
mov    %eax,%edx
call   10b0 <read@plt>
mov    %eax,-0x48(%rbp)
cmpl   $0xffffffff,-0x48(%rbp)
jne    14c7 <sdialog_call_modal+0x277>
mov    0x2b21(%rip),%rax
mov    (%rax),%rax
mov    0x2b0f(%rip),%rcx
cmp    (%rcx),%rax
jne    14c7 <sdialog_call_modal+0x277>
jmp    14e2 <sdialog_call_modal+0x292>
cmpl   $0x0,-0x48(%rbp)
jg     14d6 <sdialog_call_modal+0x286>
jmp    14f5 <sdialog_call_modal+0x2a5>
movslq -0x48(%rbp),%rax
add    -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    $0x3ff,%eax
sub    -0x30(%rbp),%rax
cmp    $0x0,%rax
ja     147d <sdialog_call_modal+0x22d>
mov    -0x30(%rbp),%rax
movb   $0x0,-0x450(%rbp,%rax,1)
mov    -0x40(%rbp),%edi
call   1070 <close@plt>
lea    0xc57(%rip),%rdi
mov    $0x0,%al
call   1110 <dlg_log_printf@plt>
mov    -0x28(%rbp),%rdi
lea    -0x44(%rbp),%rsi
xor    %edx,%edx
call   1100 <waitpid@plt>
cmp    $0x0,%rax
jge    1573 <sdialog_call_modal+0x323>
mov    0x2a99(%rip),%rax
mov    (%rax),%rax
mov    0x2a87(%rip),%rcx
cmp    (%rcx),%rax
je     156e <sdialog_call_modal+0x31e>
mov    0x2a7f(%rip),%rax
mov    (%rax),%rdi
call   1160 <strerror@plt>
mov    %eax,%esi
lea    0xc33(%rip),%rdi
mov    $0x0,%al
call   1110 <dlg_log_printf@plt>
jmp    1573 <sdialog_call_modal+0x323>
jmp    1517 <sdialog_call_modal+0x2c7>
mov    -0x44(%rbp),%edi
call   1120 <WIFEXITED@plt>
cmp    $0x0,%eax
je     1595 <sdialog_call_modal+0x345>
mov    -0x44(%rbp),%edi
call   10f0 <WEXITSTATUS@plt>
cmp    $0x1,%eax
jle    15e1 <sdialog_call_modal+0x391>
mov    -0x44(%rbp),%edi
call   1120 <WIFEXITED@plt>
mov    %eax,-0x45c(%rbp)
mov    -0x44(%rbp),%edi
call   10f0 <WEXITSTATUS@plt>
mov    -0x45c(%rbp),%esi
mov    %eax,%edx
lea    0xc0e(%rip),%rdi
mov    $0x0,%al
call   1110 <dlg_log_printf@plt>
lea    -0x450(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
movq   $0x0,-0x8(%rbp)
jmp    1635 <sdialog_call_modal+0x3e5>
lea    0xc14(%rip),%rdi
mov    $0x0,%al
call   1110 <dlg_log_printf@plt>
lea    -0x450(%rbp),%rdi
lea    0xc28(%rip),%rsi
call   10a0 <strcspn@plt>
movb   $0x0,-0x450(%rbp,%rax,1)
lea    -0x450(%rbp),%rdi
call   1140 <strdup@plt>
mov    %rax,-0x38(%rbp)
lea    -0x450(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x460,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sdialog_call_modal>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
lea    0xd8f(%rip),%rdi
xor    %eax,%eax
call   1110 <dlg_log_printf@plt>
mov    0x2d41(%rip),%rax
mov    (%rax),%edi
call   10e0 <fflush@plt>
test   %rax,%rax
je     12ae <sdialog_call_modal+0x5e>
lea    0xd7a(%rip),%rdi
call   1090 <dlg_log_error@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd71(%rip),%rdi
xor    %eax,%eax
call   1110 <dlg_log_printf@plt>
lea    0x8(%rsp),%rdi
call   1080 <pipe@plt>
test   %rax,%rax
js     141a <sdialog_call_modal+0x1ca>
lea    0xd72(%rip),%rdi
xor    %eax,%eax
call   1110 <dlg_log_printf@plt>
xor    %eax,%eax
call   1170 <fork@plt>
test   %rax,%rax
js     1426 <sdialog_call_modal+0x1d6>
je     1478 <sdialog_call_modal+0x228>
mov    %rax,%r13
lea    0xe24(%rip),%rdi
xor    %ebx,%ebx
mov    %rax,%rsi
xor    %eax,%eax
call   1110 <dlg_log_printf@plt>
lea    0xe33(%rip),%rdi
xor    %eax,%eax
call   1110 <dlg_log_printf@plt>
mov    0xc(%rsp),%edi
call   1070 <close@plt>
mov    0x2ca9(%rip),%r14
mov    0x2c9a(%rip),%rbp
jmp    1342 <sdialog_call_modal+0xf2>
mov    (%r14),%rax
cmp    0x0(%rbp),%rax
jne    1376 <sdialog_call_modal+0x126>
cmp    $0x3ff,%rbx
je     1371 <sdialog_call_modal+0x121>
mov    0x8(%rsp),%edi
lea    (%rsp,%rbx,1),%rsi
add    $0x10,%rsi
mov    $0x3ff,%edx
sub    %ebx,%edx
call   10b0 <read@plt>
cmp    $0xffffffff,%eax
je     1330 <sdialog_call_modal+0xe0>
test   %eax,%eax
jle    1376 <sdialog_call_modal+0x126>
mov    %eax,%eax
add    %rax,%rbx
cmp    $0x3ff,%rbx
jne    1342 <sdialog_call_modal+0xf2>
mov    $0x3ff,%ebx
movb   $0x0,0x10(%rsp,%rbx,1)
mov    0x8(%rsp),%edi
call   1070 <close@plt>
lea    0xddc(%rip),%rdi
xor    %eax,%eax
call   1110 <dlg_log_printf@plt>
lea    0x4(%rsp),%rbx
nopw   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
call   1100 <waitpid@plt>
test   %rax,%rax
jns    13d0 <sdialog_call_modal+0x180>
mov    (%r14),%rdi
cmp    0x0(%rbp),%rdi
je     13a0 <sdialog_call_modal+0x150>
call   1160 <strerror@plt>
lea    0xdce(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1110 <dlg_log_printf@plt>
mov    0x4(%rsp),%edi
call   1120 <WIFEXITED@plt>
test   %eax,%eax
je     13eb <sdialog_call_modal+0x19b>
mov    0x4(%rsp),%edi
call   10f0 <WEXITSTATUS@plt>
cmp    $0x2,%eax
jl     1432 <sdialog_call_modal+0x1e2>
mov    0x4(%rsp),%edi
call   1120 <WIFEXITED@plt>
mov    %eax,%ebp
mov    0x4(%rsp),%edi
call   10f0 <WEXITSTATUS@plt>
lea    0xdc2(%rip),%rdi
xor    %ebx,%ebx
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1110 <dlg_log_printf@plt>
lea    0x10(%rsp),%rdi
jmp    1467 <sdialog_call_modal+0x217>
lea    0xc0f(%rip),%rdi
jmp    1292 <sdialog_call_modal+0x42>
lea    0xc25(%rip),%rdi
jmp    1292 <sdialog_call_modal+0x42>
lea    0xdc3(%rip),%rdi
xor    %eax,%eax
call   1110 <dlg_log_printf@plt>
lea    0xdde(%rip),%rsi
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
call   10a0 <strcspn@plt>
movb   $0x0,0x10(%rsp,%rax,1)
mov    %rbp,%rdi
call   1140 <strdup@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
jmp    1299 <sdialog_call_modal+0x49>
lea    0xbeb(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
mov    0x2b4a(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xbda(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    0x0(%rbp),%edi
test   %rbx,%rbx
jne    14b7 <sdialog_call_modal+0x267>
lea    0xc02(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
jmp    14c8 <sdialog_call_modal+0x278>
lea    0xbd2(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   10c0 <fprintf@plt>
xor    %edi,%edi
call   10d0 <umask@plt>
lea    0xbeb(%rip),%rdi
call   1040 <chdir@plt>
mov    0x8(%rsp),%edi
call   1070 <close@plt>
mov    0xc(%rsp),%edi
mov    0x2b01(%rip),%rax
mov    (%rax),%esi
call   1050 <dup2@plt>
mov    0x0(%rbp),%edi
test   %rax,%rax
jns    1507 <sdialog_call_modal+0x2b7>
lea    0xbbe(%rip),%rsi
jmp    1536 <sdialog_call_modal+0x2e6>
lea    0xbd3(%rip),%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    %r12,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
mov    %r15,%rcx
xor    %r8d,%r8d
call   1150 <execlp@plt>
mov    0x0(%rbp),%edi
lea    0xbd1(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"... fflush\0A\00"
@stdout = global i32 0
@.str.1 = [26 x i8] c"sdialog_call_modal/fflush\00"
@.str.2 = [10 x i8] c"... pipe\0A\00"
@.str.3 = [24 x i8] c"sdialog_call_modal/pipe\00"
@.str.4 = [10 x i8] c"... fork\0A\00"
@.str.5 = [24 x i8] c"sdialog_call_modal/fork\00"
@.str.6 = [8 x i8] c"DISPLAY\00"
@stderr = global i32 0
@.str.7 = [30 x i8] c"sdialog_call_modal: in child\0A\00"
@.str.8 = [32 x i8] c"sdialog_call_modal: DISPLAY=%s\0A\00"
@.str.9 = [17 x i8] c"DISPLAY not set\0A\00"
@.str.10 = [2 x i8] c"/\00"
@STDOUT_FILENO = global i32 0
@.str.11 = [30 x i8] c"sdialog_call_modal/child/dup2\00"
@.str.12 = [38 x i8] c"call_dialog_result: about to exec %s\0A\00"
@.str.13 = [26 x i8] c"sdialog_call_modal/execlp\00"
@.str.14 = [34 x i8] c"sdialog_call_modal: child PID=%d\0A\00"
@.str.15 = [36 x i8] c"sdialog_call_modal: reading result\0A\00"
@errno = global i64 0
@EINTR = global i64 0
@.str.16 = [46 x i8] c"sdialog_call_modal: waiting for child to die\0A\00"
@.str.17 = [51 x i8] c"sdialog_call_modal: waitpid returned with error %s\00"
@.str.18 = [52 x i8] c"sdialog_call_modal: child died badly: if %d, st %d\0A\00"
@.str.19 = [41 x i8] c"sdialog_call_modal: child died normally\0A\00"
@.str.20 = [3 x i8] c"\0D\0A\00"
define i8* @sdialog_call_modal(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i8*
%11 = alloca [2 x i32]
%12 = alloca i32
%13 = alloca i32
%14 = alloca [1024 x i8]
%15 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%16 = call i32 (i8*, ...) @dlg_log_printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* @stdout
%18 = call i64 @fflush(i32 %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %3
%21 = call i32 @dlg_log_error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
store i8* null, i8** %4
br label %161
22: ; preds = %3
%23 = call i32 (i8*, ...) @dlg_log_printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %11, i64 0, i64 0
%25 = call i64 @pipe(i32* %24)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %22
%28 = call i32 @dlg_log_error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
store i8* null, i8** %4
br label %161
29: ; preds = %22
%30 = call i32 (i8*, ...) @dlg_log_printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%31 = call i64 (...) @fork()
store i64 %31, i64* %8
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %29
%34 = call i32 @dlg_log_error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
store i8* null, i8** %4
br label %161
35: ; preds = %29
%36 = load i64, i64* %8
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %78
38: ; preds = %35
%39 = call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
store i8* %39, i8** %15
%40 = load i32, i32* @stderr
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0))
%42 = load i8*, i8** %15
%43 = icmp ne i8* %42, null
br i1 %43, label %44, label %48
44: ; preds = %38
%45 = load i32, i32* @stderr
%46 = load i8*, i8** %15
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.8, i64 0, i64 0), i8* %46)
br label %51
48: ; preds = %38
%49 = load i32, i32* @stderr
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0))
br label %51
51: ; preds = %48, %44
%52 = call i32 @umask(i32 0)
%53 = call i32 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
%54 = getelementptr inbounds [2 x i32], [2 x i32]* %11, i64 0, i64 0
%55 = load i32, i32* %54
%56 = call i32 @close(i32 %55)
%57 = getelementptr inbounds [2 x i32], [2 x i32]* %11, i64 0, i64 1
%58 = load i32, i32* %57
%59 = load i32, i32* @STDOUT_FILENO
%60 = call i64 @dup2(i32 %58, i32 %59)
%61 = icmp slt i64 %60, 0
br i1 %61, label %62, label %66
62: ; preds = %51
%63 = load i32, i32* @stderr
%64 = call i32 (i32, i8*, ...) @fprintf(i32 %63, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.11, i64 0, i64 0))
%65 = call i32 @exit(i32 1)
unreachable
66: ; preds = %51
%67 = load i32, i32* @stderr
%68 = load i8*, i8** %5
%69 = call i32 (i32, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.12, i64 0, i64 0), i8* %68)
%70 = load i8*, i8** %5
%71 = load i8*, i8** %5
%72 = load i8*, i8** %7
%73 = load i8*, i8** %6
%74 = call i32 @execlp(i8* %70, i8* %71, i8* %72, i8* %73, i8* null)
%75 = load i32, i32* @stderr
%76 = call i32 (i32, i8*, ...) @fprintf(i32 %75, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.13, i64 0, i64 0))
%77 = call i32 @exit(i32 1)
unreachable
78: ; preds = %35
%79 = load i64, i64* %8
%80 = call i32 (i8*, ...) @dlg_log_printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.14, i64 0, i64 0), i64 %79)
%81 = call i32 (i8*, ...) @dlg_log_printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.15, i64 0, i64 0))
%82 = getelementptr inbounds [2 x i32], [2 x i32]* %11, i64 0, i64 1
%83 = load i32, i32* %82
%84 = call i32 @close(i32 %83)
store i32 0, i32* %13
store i64 0, i64* %9
br label %85
85: ; preds = %111, %78
%86 = getelementptr inbounds [2 x i32], [2 x i32]* %11, i64 0, i64 0
%87 = load i32, i32* %86
%88 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%89 = load i64, i64* %9
%90 = getelementptr inbounds i8, i8* %88, i64 %89
%91 = load i64, i64* %9
%92 = sub i64 1023, %91
%93 = trunc i64 %92 to i32
%94 = call i32 @read(i32 %87, i8* %90, i32 %93)
store i32 %94, i32* %13
%95 = load i32, i32* %13
%96 = icmp eq i32 %95, -1
br i1 %96, label %97, label %102
97: ; preds = %85
%98 = load i64, i64* @errno
%99 = load i64, i64* @EINTR
%100 = icmp eq i64 %98, %99
br i1 %100, label %101, label %102
101: ; preds = %97
br label %111
102: ; preds = %97, %85
%103 = load i32, i32* %13
%104 = icmp sle i32 %103, 0
br i1 %104, label %105, label %106
105: ; preds = %102
br label %115
106: ; preds = %102
%107 = load i32, i32* %13
%108 = sext i32 %107 to i64
%109 = load i64, i64* %9
%110 = add i64 %109, %108
store i64 %110, i64* %9
br label %111
111: ; preds = %106, %101
%112 = load i64, i64* %9
%113 = sub i64 1023, %112
%114 = icmp ugt i64 %113, 0
br i1 %114, label %85, label %115
115: ; preds = %111, %105
%116 = load i64, i64* %9
%117 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 %116
store i8 0, i8* %117
%118 = getelementptr inbounds [2 x i32], [2 x i32]* %11, i64 0, i64 0
%119 = load i32, i32* %118
%120 = call i32 @close(i32 %119)
%121 = call i32 (i8*, ...) @dlg_log_printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.16, i64 0, i64 0))
br label %122
122: ; preds = %134, %115
%123 = load i64, i64* %8
%124 = call i64 @waitpid(i64 %123, i32* %12, i32 0)
%125 = icmp slt i64 %124, 0
br i1 %125, label %126, label %135
126: ; preds = %122
%127 = load i64, i64* @errno
%128 = load i64, i64* @EINTR
%129 = icmp ne i64 %127, %128
br i1 %129, label %130, label %134
130: ; preds = %126
%131 = load i64, i64* @errno
%132 = call i32 @strerror(i64 %131)
%133 = call i32 (i8*, ...) @dlg_log_printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.17, i64 0, i64 0), i32 %132)
br label %135
134: ; preds = %126
br label %122
135: ; preds = %130, %122
%136 = load i32, i32* %12
%137 = call i32 @WIFEXITED(i32 %136)
%138 = icmp ne i32 %137, 0
br i1 %138, label %139, label %143
139: ; preds = %135
%140 = load i32, i32* %12
%141 = call i32 @WEXITSTATUS(i32 %140)
%142 = icmp sgt i32 %141, 1
br i1 %142, label %143, label %151
143: ; preds = %139, %135
%144 = load i32, i32* %12
%145 = call i32 @WIFEXITED(i32 %144)
%146 = load i32, i32* %12
%147 = call i32 @WEXITSTATUS(i32 %146)
%148 = call i32 (i8*, ...) @dlg_log_printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.18, i64 0, i64 0), i32 %145, i32 %147)
%149 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%150 = call i32 @memset(i8* %149, i32 0, i32 1024)
store i8* null, i8** %4
br label %161
151: ; preds = %139
%152 = call i32 (i8*, ...) @dlg_log_printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.19, i64 0, i64 0))
%153 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%154 = call i64 @strcspn(i8* %153, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.20, i64 0, i64 0))
%155 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 %154
store i8 0, i8* %155
%156 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%157 = call i8* @strdup(i8* %156)
store i8* %157, i8** %10
%158 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%159 = call i32 @memset(i8* %158, i32 0, i32 1024)
%160 = load i8*, i8** %10
store i8* %160, i8** %4
br label %161
161: ; preds = %151, %143, %33, %27, %20
%162 = load i8*, i8** %4
ret i8* %162
}

LLVM IR (-O2):
@.str = [12 x i8] c"... fflush\0A\00"
@stdout = global i32 0
@.str.1 = [26 x i8] c"sdialog_call_modal/fflush\00"
@.str.2 = [10 x i8] c"... pipe\0A\00"
@.str.3 = [24 x i8] c"sdialog_call_modal/pipe\00"
@.str.4 = [10 x i8] c"... fork\0A\00"
@.str.5 = [24 x i8] c"sdialog_call_modal/fork\00"
@.str.6 = [8 x i8] c"DISPLAY\00"
@stderr = global i32 0
@.str.7 = [30 x i8] c"sdialog_call_modal: in child\0A\00"
@.str.8 = [32 x i8] c"sdialog_call_modal: DISPLAY=%s\0A\00"
@.str.9 = [17 x i8] c"DISPLAY not set\0A\00"
@.str.10 = [2 x i8] c"/\00"
@STDOUT_FILENO = global i32 0
@.str.11 = [30 x i8] c"sdialog_call_modal/child/dup2\00"
@.str.12 = [38 x i8] c"call_dialog_result: about to exec %s\0A\00"
@.str.13 = [26 x i8] c"sdialog_call_modal/execlp\00"
@.str.14 = [34 x i8] c"sdialog_call_modal: child PID=%d\0A\00"
@.str.15 = [36 x i8] c"sdialog_call_modal: reading result\0A\00"
@errno = global i64 0
@EINTR = global i64 0
@.str.16 = [46 x i8] c"sdialog_call_modal: waiting for child to die\0A\00"
@.str.17 = [51 x i8] c"sdialog_call_modal: waitpid returned with error %s\00"
@.str.18 = [52 x i8] c"sdialog_call_modal: child died badly: if %d, st %d\0A\00"
@.str.19 = [41 x i8] c"sdialog_call_modal: child died normally\0A\00"
@.str.20 = [3 x i8] c"\0D\0A\00"
define noalias i8* @sdialog_call_modal(i8* %0, i8* %1, i8* %2) {
%4 = alloca [2 x i32]
%5 = alloca i32
%6 = alloca [1024 x i8]
%7 = bitcast [2 x i32]* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%10 = tail call i32 (i8*, ...) @dlg_log_printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @stdout
%12 = tail call i64 @fflush(i32 %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %3
%15 = tail call i32 @dlg_log_error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %124
16: ; preds = %3
%17 = tail call i32 (i8*, ...) @dlg_log_printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%18 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%19 = call i64 @pipe(i32* %18)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = call i32 @dlg_log_error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %124
23: ; preds = %16
%24 = call i32 (i8*, ...) @dlg_log_printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%25 = call i64 (...) @fork()
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = call i32 @dlg_log_error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
br label %124
29: ; preds = %23
%30 = icmp eq i64 %25, 0
br i1 %30, label %31, label %61
31: ; preds = %29
%32 = call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%33 = load i32, i32* @stderr
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0))
%35 = icmp eq i8* %32, null
%36 = load i32, i32* @stderr
br i1 %35, label %39, label %37
37: ; preds = %31
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.8, i64 0, i64 0), i8* %32)
br label %41
39: ; preds = %31
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0))
br label %41
41: ; preds = %39, %37
%42 = call i32 @umask(i32 0)
%43 = call i32 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
%44 = load i32, i32* %18
%45 = call i32 @close(i32 %44)
%46 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%47 = load i32, i32* %46
%48 = load i32, i32* @STDOUT_FILENO
%49 = call i64 @dup2(i32 %47, i32 %48)
%50 = icmp slt i64 %49, 0
%51 = load i32, i32* @stderr
br i1 %50, label %52, label %55
52: ; preds = %41
%53 = call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.11, i64 0, i64 0))
%54 = call i32 @exit(i32 1)
unreachable
55: ; preds = %41
%56 = call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.12, i64 0, i64 0), i8* %0)
%57 = call i32 @execlp(i8* %0, i8* %0, i8* %2, i8* %1, i8* null)
%58 = load i32, i32* @stderr
%59 = call i32 (i32, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.13, i64 0, i64 0))
%60 = call i32 @exit(i32 1)
unreachable
61: ; preds = %29
%62 = call i32 (i8*, ...) @dlg_log_printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.14, i64 0, i64 0), i64 %25)
%63 = call i32 (i8*, ...) @dlg_log_printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.15, i64 0, i64 0))
%64 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%65 = load i32, i32* %64
%66 = call i32 @close(i32 %65)
br label %67
67: ; preds = %84, %61
%68 = phi i64 [ 0, %61 ], [ %85, %84 ]
%69 = load i32, i32* %18
%70 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %68
%71 = trunc i64 %68 to i32
%72 = sub i32 1023, %71
%73 = call i32 @read(i32 %69, i8* %70, i32 %72)
%74 = icmp eq i32 %73, -1
br i1 %74, label %75, label %79
75: ; preds = %67
%76 = load i64, i64* @errno
%77 = load i64, i64* @EINTR
%78 = icmp eq i64 %76, %77
br i1 %78, label %84, label %87
79: ; preds = %67
%80 = icmp slt i32 %73, 1
br i1 %80, label %87, label %81
81: ; preds = %79
%82 = zext i32 %73 to i64
%83 = add i64 %68, %82
br label %84
84: ; preds = %75, %81
%85 = phi i64 [ %68, %75 ], [ %83, %81 ]
%86 = icmp eq i64 %85, 1023
br i1 %86, label %87, label %67
87: ; preds = %75, %79, %84
%88 = phi i64 [ 1023, %84 ], [ %68, %79 ], [ %68, %75 ]
%89 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %88
store i8 0, i8* %89
%90 = load i32, i32* %18
%91 = call i32 @close(i32 %90)
%92 = call i32 (i8*, ...) @dlg_log_printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.16, i64 0, i64 0))
br label %93
93: ; preds = %96, %87
%94 = call i64 @waitpid(i64 %25, i32* %5, i32 0)
%95 = icmp slt i64 %94, 0
br i1 %95, label %96, label %103
96: ; preds = %93
%97 = load i64, i64* @errno
%98 = load i64, i64* @EINTR
%99 = icmp eq i64 %97, %98
br i1 %99, label %93, label %100
100: ; preds = %96
%101 = call i32 @strerror(i64 %97)
%102 = call i32 (i8*, ...) @dlg_log_printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.17, i64 0, i64 0), i32 %101)
br label %103
103: ; preds = %93, %100
%104 = load i32, i32* %5
%105 = call i32 @WIFEXITED(i32 %104)
%106 = icmp eq i32 %105, 0
br i1 %106, label %111, label %107
107: ; preds = %103
%108 = load i32, i32* %5
%109 = call i32 @WEXITSTATUS(i32 %108)
%110 = icmp sgt i32 %109, 1
br i1 %110, label %111, label %118
111: ; preds = %107, %103
%112 = load i32, i32* %5
%113 = call i32 @WIFEXITED(i32 %112)
%114 = load i32, i32* %5
%115 = call i32 @WEXITSTATUS(i32 %114)
%116 = call i32 (i8*, ...) @dlg_log_printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.18, i64 0, i64 0), i32 %113, i32 %115)
%117 = call i32 @memset(i8* %9, i32 0, i32 1024)
br label %124
118: ; preds = %107
%119 = call i32 (i8*, ...) @dlg_log_printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.19, i64 0, i64 0))
%120 = call i64 @strcspn(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.20, i64 0, i64 0))
%121 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %120
store i8 0, i8* %121
%122 = call i8* @strdup(i8* %9)
%123 = call i32 @memset(i8* %9, i32 0, i32 1024)
br label %124
124: ; preds = %118, %111, %27, %21, %14
%125 = phi i8* [ null, %14 ], [ null, %21 ], [ null, %27 ], [ null, %111 ], [ %122, %118 ]
ret i8* %125
}