#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 long pid_t;

/* Variables and functions */
int /*<<< orphan*/ chdir(char *);
int /*<<< orphan*/ dlg_log_error(char *);
int /*<<< orphan*/ dlg_log_printf(char *, ...);
int /*<<< orphan*/ execlp(char const *, char const *, char const *,
                          char const *, char *);
int /*<<< orphan*/ exit(int);
long fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
char *getenv(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ umask(int /*<<< orphan*/);
pid_t sdialog_call(const char *path, const char *msg, const char *pinName) {
  pid_t pid;
  dlg_log_printf("sdialog_call/fork\n");
  if ((pid = fork()) < 0) {
    dlg_log_error("sdialog_call/fork");
    return 0L;
  }
  if (pid == 0) {
    char *disp = getenv("DISPLAY");
    dlg_log_printf("sdialog_call: in child\n");
    if (disp != NULL) {
      fprintf(stderr, "sdialog_call: DISPLAY=%s\n", disp);
    } else {
      fprintf(stderr, "DISPLAY not set\n");
    }
    umask(0);
    chdir("/");
    fprintf(stderr, "call_dialog: about to exec %s\n", path);
    execlp(path, path, pinName, msg, (char *)0);
    perror("sdialog_call/execlp");
    exit(1);
  }
  dlg_log_printf("sdialog_call: child PID=%d\n", pid);
  return pid;
}


x86 assembly (clang, -O0):
<sdialog_call>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1090 <dlg_log_printf@plt>
mov    $0x0,%al
call   10c0 <fork@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jge    11f0 <sdialog_call+0x50>
lea    0xe35(%rip),%rdi
call   1050 <dlg_log_error@plt>
movq   $0x0,-0x8(%rbp)
jmp    12d3 <sdialog_call+0x133>
cmpq   $0x0,-0x28(%rbp)
jne    12b9 <sdialog_call+0x119>
lea    0xe23(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x30(%rbp)
lea    0xe1b(%rip),%rdi
mov    $0x0,%al
call   1090 <dlg_log_printf@plt>
cmpq   $0x0,-0x30(%rbp)
je     1244 <sdialog_call+0xa4>
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rdx
lea    0xe0d(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    125b <sdialog_call+0xbb>
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
lea    0xe0b(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
xor    %edi,%edi
call   1070 <umask@plt>
lea    0xe07(%rip),%rdi
call   1040 <chdir@plt>
mov    0x2d6b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xdf0(%rip),%rsi
mov    $0x0,%al
call   1060 <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   10b0 <execlp@plt>
lea    0xde7(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x28(%rbp),%rsi
lea    0xde1(%rip),%rdi
mov    $0x0,%al
call   1090 <dlg_log_printf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sdialog_call>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
lea    0xe47(%rip),%rdi
xor    %eax,%eax
call   1090 <dlg_log_printf@plt>
xor    %eax,%eax
call   10c0 <fork@plt>
test   %rax,%rax
js     11e4 <sdialog_call+0x44>
je     11ff <sdialog_call+0x5f>
mov    %rax,%rbx
lea    0xecd(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1090 <dlg_log_printf@plt>
jmp    11f2 <sdialog_call+0x52>
lea    0xe28(%rip),%rdi
call   1050 <dlg_log_error@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xe1f(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
lea    0xe18(%rip),%rdi
xor    %eax,%eax
call   1090 <dlg_log_printf@plt>
mov    0x2dbd(%rip),%r13
mov    0x0(%r13),%edi
test   %rbx,%rbx
jne    123c <sdialog_call+0x9c>
lea    0xe2c(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    124d <sdialog_call+0xad>
lea    0xe02(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
xor    %edi,%edi
call   1070 <umask@plt>
lea    0xe15(%rip),%rdi
call   1040 <chdir@plt>
mov    0x0(%r13),%edi
lea    0xe07(%rip),%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r12,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
mov    %r15,%rcx
xor    %r8d,%r8d
call   10b0 <execlp@plt>
lea    0xe01(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"sdialog_call/fork\0A\00"
@.str.1 = [18 x i8] c"sdialog_call/fork\00"
@.str.2 = [8 x i8] c"DISPLAY\00"
@.str.3 = [24 x i8] c"sdialog_call: in child\0A\00"
@stderr = global i32 0
@.str.4 = [26 x i8] c"sdialog_call: DISPLAY=%s\0A\00"
@.str.5 = [17 x i8] c"DISPLAY not set\0A\00"
@.str.6 = [2 x i8] c"/\00"
@.str.7 = [31 x i8] c"call_dialog: about to exec %s\0A\00"
@.str.8 = [20 x i8] c"sdialog_call/execlp\00"
@.str.9 = [28 x i8] c"sdialog_call: child PID=%d\0A\00"
define i64 @sdialog_call(i8* %0, i8* %1, i8* %2) {
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%10 = call i32 (i8*, ...) @dlg_log_printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%11 = call i64 (...) @fork()
store i64 %11, i64* %8
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %3
%14 = call i32 @dlg_log_error(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
store i64 0, i64* %4
br label %47
15: ; preds = %3
%16 = load i64, i64* %8
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %43
18: ; preds = %15
%19 = call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
store i8* %19, i8** %9
%20 = call i32 (i8*, ...) @dlg_log_printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%21 = load i8*, i8** %9
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %27
23: ; preds = %18
%24 = load i32, i32* @stderr
%25 = load i8*, i8** %9
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %25)
br label %30
27: ; preds = %18
%28 = load i32, i32* @stderr
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
br label %30
30: ; preds = %27, %23
%31 = call i32 @umask(i32 0)
%32 = call i32 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%33 = load i32, i32* @stderr
%34 = load i8*, i8** %5
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0), i8* %34)
%36 = load i8*, i8** %5
%37 = load i8*, i8** %5
%38 = load i8*, i8** %7
%39 = load i8*, i8** %6
%40 = call i32 @execlp(i8* %36, i8* %37, i8* %38, i8* %39, i8* null)
%41 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0))
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %15
%44 = load i64, i64* %8
%45 = call i32 (i8*, ...) @dlg_log_printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.9, i64 0, i64 0), i64 %44)
%46 = load i64, i64* %8
store i64 %46, i64* %4
br label %47
47: ; preds = %43, %13
%48 = load i64, i64* %4
ret i64 %48
}

LLVM IR (-O2):
@.str = [19 x i8] c"sdialog_call/fork\0A\00"
@.str.1 = [18 x i8] c"sdialog_call/fork\00"
@.str.2 = [8 x i8] c"DISPLAY\00"
@.str.3 = [24 x i8] c"sdialog_call: in child\0A\00"
@stderr = global i32 0
@.str.4 = [26 x i8] c"sdialog_call: DISPLAY=%s\0A\00"
@.str.5 = [17 x i8] c"DISPLAY not set\0A\00"
@.str.6 = [2 x i8] c"/\00"
@.str.7 = [31 x i8] c"call_dialog: about to exec %s\0A\00"
@.str.8 = [20 x i8] c"sdialog_call/execlp\00"
@.str.9 = [28 x i8] c"sdialog_call: child PID=%d\0A\00"
define i64 @sdialog_call(i8* %0, i8* %1, i8* %2) {
%4 = tail call i32 (i8*, ...) @dlg_log_printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%5 = tail call i64 (...) @fork()
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 @dlg_log_error(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %30
9: ; preds = %3
%10 = icmp eq i64 %5, 0
br i1 %10, label %11, label %28
11: ; preds = %9
%12 = tail call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%13 = tail call i32 (i8*, ...) @dlg_log_printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%14 = icmp eq i8* %12, null
%15 = load i32, i32* @stderr
br i1 %14, label %18, label %16
16: ; preds = %11
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %12)
br label %20
18: ; preds = %11
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
br label %20
20: ; preds = %18, %16
%21 = tail call i32 @umask(i32 0)
%22 = tail call i32 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%23 = load i32, i32* @stderr
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0), i8* %0)
%25 = tail call i32 @execlp(i8* %0, i8* %0, i8* %2, i8* %1, i8* null)
%26 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0))
%27 = tail call i32 @exit(i32 1)
unreachable
28: ; preds = %9
%29 = tail call i32 (i8*, ...) @dlg_log_printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.9, i64 0, i64 0), i64 %5)
br label %30
30: ; preds = %28, %7
%31 = phi i64 [ 0, %7 ], [ %5, %28 ]
ret i64 %31
}