#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 engine_daemon();
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ printf(char *, ...);
int init_audio_engine() {
  int pid, err;
  pid = fork();
  if (pid < 0) {
    printf("fork error, exiting..\n");
    exit(1);
  }
  if (pid > 0) {
    printf("audio engine pid: %d\n", pid);
    return (pid);
  }
  err = engine_daemon();
  if (!err) {
    exit(0);
  }
  printf("audio daemon exited with error\n");
  exit(1);
}


x86 assembly (clang, -O0):
<init_audio_engine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1060 <fork@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    1174 <init_audio_engine+0x34>
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
cmpl   $0x0,-0x4(%rbp)
jle    1198 <init_audio_engine+0x58>
mov    -0x4(%rbp),%esi
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret
mov    $0x0,%al
call   1040 <engine_daemon@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    11b3 <init_audio_engine+0x73>
xor    %edi,%edi
call   1050 <exit@plt>
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<init_audio_engine>:
push   %rbx
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
js     1174 <init_audio_engine+0x24>
je     117d <init_audio_engine+0x2d>
mov    %eax,%ebx
lea    0xe99(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%eax
pop    %rbx
ret
lea    0xeba(%rip),%rdi
jmp    1196 <init_audio_engine+0x46>
xor    %eax,%eax
call   1050 <engine_daemon@plt>
test   %eax,%eax
jne    118f <init_audio_engine+0x3f>
xor    %edi,%edi
call   1060 <exit@plt>
lea    0xe80(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [23 x i8] c"fork error, exiting..\0A\00"
@.str.1 = [22 x i8] c"audio engine pid: %d\0A\00"
@.str.2 = [32 x i8] c"audio daemon exited with error\0A\00"
define i32 @init_audio_engine() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 (...) @fork()
store i32 %3, i32* %1
%4 = load i32, i32* %1
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @exit(i32 1)
unreachable
9: ; preds = %0
%10 = load i32, i32* %1
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = load i32, i32* %1
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = load i32, i32* %1
ret i32 %15
16: ; preds = %9
%17 = call i32 (...) @engine_daemon()
store i32 %17, i32* %2
%18 = load i32, i32* %2
%19 = icmp ne i32 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %16
%21 = call i32 @exit(i32 0)
unreachable
22: ; preds = %16
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
@.str.1 = [22 x i8] c"audio engine pid: %d\0A\00"
@str = [31 x i8] c"audio daemon exited with error\00"
@str.3 = [22 x i8] c"fork error, exiting..\00"
define i32 @init_audio_engine() {
%1 = tail call i32 (...) @fork()
%2 = icmp slt i32 %1, 0
br i1 %2, label %3, label %6
3: ; preds = %0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.3, i64 0, i64 0))
%5 = tail call i32 @exit(i32 1)
unreachable
6: ; preds = %0
%7 = icmp eq i32 %1, 0
br i1 %7, label %10, label %8
8: ; preds = %6
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %1)
ret i32 %1
10: ; preds = %6
%11 = tail call i32 (...) @engine_daemon()
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = tail call i32 @exit(i32 0)
unreachable
15: ; preds = %10
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%17 = tail call i32 @exit(i32 1)
unreachable
}