#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 /*<<< orphan*/ doService(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int getpid();
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
doServiceFork(int fd) {
  int res = fork();
  if (res == 0) {
    char buff2[80];
    sprintf(buff2, "Server PID =  %d \n", getpid());
    write(1, buff2, strlen(buff2));
    doService(fd);
    exit(0);
  }
}


x86 assembly (clang, -O0):
<doServiceFork>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x8(%rbp)
mov    $0x0,%al
call   1090 <fork@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    11e0 <doServiceFork+0x70>
lea    -0x60(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x70(%rbp),%rdi
mov    %eax,%edx
lea    0xe55(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x60(%rbp),%rax
mov    %rax,-0x68(%rbp)
lea    -0x60(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x68(%rbp),%rsi
mov    %eax,%edx
mov    $0x1,%edi
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
call   1060 <doService@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<doServiceFork>:
push   %r14
push   %rbx
sub    $0x58,%rsp
mov    %edi,%ebx
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
je     118c <doServiceFork+0x1c>
add    $0x58,%rsp
pop    %rbx
pop    %r14
ret
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe66(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
mov    %eax,%edx
call   1070 <sprintf@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    $0x1,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %ebx,%edi
call   1060 <doService@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"Server PID = %d \0A\00"
define i32 @doServiceFork(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [80 x i8]
store i32 %0, i32* %3
%6 = call i32 (...) @fork()
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %20
9: ; preds = %1
%10 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%11 = call i32 (...) @getpid()
%12 = call i32 @sprintf(i8* %10, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%14 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%15 = call i32 @strlen(i8* %14)
%16 = call i32 @write(i32 1, i8* %13, i32 %15)
%17 = load i32, i32* %3
%18 = call i32 @doService(i32 %17)
%19 = call i32 @exit(i32 0)
unreachable
20: ; preds = %1
%21 = load i32, i32* %2
ret i32 %21
}

LLVM IR (-O2):
@.str = [19 x i8] c"Server PID = %d \0A\00"
define i32 @doServiceFork(i32 %0) {
%2 = alloca [80 x i8]
%3 = tail call i32 (...) @fork()
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %13
5: ; preds = %1
%6 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%7 = tail call i32 (...) @getpid()
%8 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = call i32 @strlen(i8* %6)
%10 = call i32 @write(i32 1, i8* %6, i32 %9)
%11 = call i32 @doService(i32 %0)
%12 = call i32 @exit(i32 0)
unreachable
13: ; preds = %1
ret i32 undef
}