#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 */
struct dirent {
  int dummy;
};
typedef int /*<<< orphan*/ pid_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ WUNTRACED;
int /*<<< orphan*/ execlp(char *, char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ tree_to_dot(int /*<<< orphan*/ *, struct dirent *);
int /*<<< orphan*/ waitpid(int /*<<< orphan*/, int *, int /*<<< orphan*/);
int show_tree(char *name, struct dirent *a, int waitfor) {
  FILE *f;
  char *buf;
  int stat;
  pid_t pid;
  if ((f = fopen(name, "w")) == NULL) {
    perror("Error opening dot output file");
    return 1;
  }
  tree_to_dot(f, a);
  fclose(f);
  if ((pid = fork()) == 0) {
    execlp("dotty", "dotty", name, NULL);
    exit(1);
  }
  if (waitfor) {
    waitpid(pid, &stat, WUNTRACED);
  }
  return 0;
}


x86 assembly (clang, -O0):
<show_tree>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe62(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11c9 <show_tree+0x49>
lea    0xe4a(%rip),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1239 <show_tree+0xb9>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1090 <tree_to_dot@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %eax,-0x38(%rbp)
cmp    $0x0,%eax
jne    1213 <show_tree+0x93>
mov    -0x10(%rbp),%rdx
lea    0xe23(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rsi,%rdi
call   1080 <execlp@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
cmpl   $0x0,-0x1c(%rbp)
je     1232 <show_tree+0xb2>
mov    -0x38(%rbp),%edi
mov    0x2db9(%rip),%rax
mov    (%rax),%edx
lea    -0x34(%rbp),%rsi
call   1040 <waitpid@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_tree>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xe69(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11eb <show_tree+0x6b>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %rbx,%rsi
call   1090 <tree_to_dot@plt>
mov    %rbp,%rdi
call   1030 <fclose@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   10a0 <fork@plt>
test   %eax,%eax
je     11fe <show_tree+0x7e>
test   %r15d,%r15d
je     11de <show_tree+0x5e>
mov    0x2e10(%rip),%rcx
mov    (%rcx),%edx
lea    0x4(%rsp),%rsi
mov    %eax,%edi
call   1040 <waitpid@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe10(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%ebx
jmp    11de <show_tree+0x5e>
lea    0xe1b(%rip),%rdi
mov    %rdi,%rsi
mov    %r14,%rdx
xor    %ecx,%ecx
call   1080 <execlp@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.dirent = type { i32 }
@.str = [2 x i8] c"w\00"
@.str.1 = [30 x i8] c"Error opening dot output file\00"
@.str.2 = [6 x i8] c"dotty\00"
@WUNTRACED = global i32 0
define i32 @show_tree(i8* %0, %struct.dirent* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca %struct.dirent*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %5
store %struct.dirent* %1, %struct.dirent** %6
store i32 %2, i32* %7
%12 = load i8*, i8** %5
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %8
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %17
15: ; preds = %3
%16 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %4
br label %37
17: ; preds = %3
%18 = load i32*, i32** %8
%19 = load %struct.dirent*, %struct.dirent** %6
%20 = call i32 @tree_to_dot(i32* %18, %struct.dirent* %19)
%21 = load i32*, i32** %8
%22 = call i32 @fclose(i32* %21)
%23 = call i32 (...) @fork()
store i32 %23, i32* %11
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %17
%26 = load i8*, i8** %5
%27 = call i32 @execlp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %26, i32* null)
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %17
%30 = load i32, i32* %7
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %29
%33 = load i32, i32* %11
%34 = load i32, i32* @WUNTRACED
%35 = call i32 @waitpid(i32 %33, i32* %10, i32 %34)
br label %36
36: ; preds = %32, %29
store i32 0, i32* %4
br label %37
37: ; preds = %36, %15
%38 = load i32, i32* %4
ret i32 %38
}

LLVM IR (-O2):
%struct.dirent = type { i32 }
@.str = [2 x i8] c"w\00"
@.str.1 = [30 x i8] c"Error opening dot output file\00"
@.str.2 = [6 x i8] c"dotty\00"
@WUNTRACED = global i32 0
define i32 @show_tree(i8* %0, %struct.dirent* %1, i32 %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = tail call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
br label %23
10: ; preds = %3
%11 = tail call i32 @tree_to_dot(i32* %6, %struct.dirent* %1)
%12 = tail call i32 @fclose(i32* %6)
%13 = tail call i32 (...) @fork()
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = tail call i32 @execlp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %0, i32* null)
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %10
%19 = icmp eq i32 %2, 0
br i1 %19, label %23, label %20
20: ; preds = %18
%21 = load i32, i32* @WUNTRACED
%22 = call i32 @waitpid(i32 %13, i32* %4, i32 %21)
br label %23
23: ; preds = %18, %20, %8
%24 = phi i32 [ 1, %8 ], [ 0, %20 ], [ 0, %18 ]
ret i32 %24
}