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

/* Variables and functions */
int /*<<< orphan*/ execlp(char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ fork();
int getpid();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  char *prompt = "slvr@slvr-prompt$";
  char s[1024];
  do {
    printf("%s", prompt);
    scanf("%s", s);
    if (!strcmp(s, "exit"))
      return 0;
    if (!strcmp(s, "PID"))
      printf("Je suis le slvr-prompt numéro %d\n", getpid());
    else {
      pid_t Pid;
      switch (Pid = fork()) {
      case -1:
        printf("Probleme : echec du fork");
        break;
      case 0:
        execlp(s, s, NULL);
        printf("L'enfant numéro %d est né !\n", getpid());
        break;
      default:
        wait(NULL);
        printf("Le slvr-prompt numéro %d est de retour !\n", getpid());
      }
    }
  } while (1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe70(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x420(%rbp),%rsi
lea    0xe5e(%rip),%rdi
call   1060 <scanf@plt>
lea    -0x420(%rbp),%rdi
lea    0xe4e(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11e1 <main+0x71>
movl   $0x0,-0x4(%rbp)
jmp    12ce <main+0x15e>
lea    -0x420(%rbp),%rdi
lea    0xe2b(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    1219 <main+0xa9>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12ba <main+0x14a>
xor    %eax,%eax
call   1090 <fork@plt>
mov    %eax,-0x424(%rbp)
mov    %eax,%ecx
mov    %ecx,-0x428(%rbp)
sub    $0xffffffff,%eax
je     124f <main+0xdf>
jmp    123c <main+0xcc>
mov    -0x428(%rbp),%eax
test   %eax,%eax
je     1262 <main+0xf2>
jmp    1295 <main+0x125>
lea    0xdeb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12b5 <main+0x145>
lea    -0x420(%rbp),%rdi
lea    -0x420(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1070 <execlp@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xdd1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12b5 <main+0x145>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <wait@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xdcb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12ba <main+0x14a>
jmp    12bf <main+0x14f>
mov    $0x1,%al
test   $0x1,%al
jne    1194 <main+0x24>
jmp    12ce <main+0x15e>
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
lea    0xe9a(%rip),%rbx
lea    0xe81(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1050 <scanf@plt>
mov    $0x74697865,%ebp
mov    (%rsp),%eax
xor    %ebp,%eax
movzbl 0x4(%rsp),%ecx
or     %eax,%ecx
je     1265 <main+0x105>
lea    0xe68(%rip),%r14
lea    0xe59(%rip),%rbx
lea    0xe40(%rip),%r15
mov    %rsp,%r12
lea    0xeab(%rip),%r13
jmp    1209 <main+0xa9>
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1050 <scanf@plt>
mov    (%rsp),%eax
xor    %ebp,%eax
movzbl 0x4(%rsp),%ecx
or     %eax,%ecx
je     1265 <main+0x105>
cmpl   $0x444950,(%rsp)
je     11d0 <main+0x70>
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     1232 <main+0xd2>
cmp    $0xffffffff,%eax
jne    124f <main+0xef>
lea    0xe14(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11e3 <main+0x83>
mov    %r12,%rdi
mov    %r12,%rsi
xor    %edx,%edx
call   1060 <execlp@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe09(%rip),%rdi
jmp    11da <main+0x7a>
xor    %edi,%edi
call   1070 <wait@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %r13,%rdi
jmp    11da <main+0x7a>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"slvr@slvr-prompt$\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [5 x i8] c"exit\00"
@.str.3 = [4 x i8] c"PID\00"
@.str.4 = [35 x i8] c"Je suis le slvr-prompt num\C3\A9ro %d\0A\00"
@.str.5 = [25 x i8] c"Probleme : echec du fork\00"
@.str.6 = [31 x i8] c"L'enfant num\C3\A9ro %d est n\C3\A9 !\0A\00"
@.str.7 = [43 x i8] c"Le slvr-prompt num\C3\A9ro %d est de retour !\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca [1024 x i8]
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8** %6
br label %9
9: ; preds = %41, %2
%10 = load i8*, i8** %6
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%15 = call i32 @strcmp(i8* %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp ne i32 %15, 0
br i1 %16, label %18, label %17
17: ; preds = %9
store i32 0, i32* %3
br label %42
18: ; preds = %9
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%20 = call i32 @strcmp(i8* %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%21 = icmp ne i32 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %18
%23 = call i32 (...) @getpid()
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i32 %23)
br label %40
25: ; preds = %18
%26 = call i32 (...) @fork()
store i32 %26, i32* %8
switch i32 %26, label %35 [
i32 -1, label %27
i32 0, label %29
]
27: ; preds = %25
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
br label %39
29: ; preds = %25
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%32 = call i32 @execlp(i8* %30, i8* %31, i32* null)
%33 = call i32 (...) @getpid()
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i32 %33)
br label %39
35: ; preds = %25
%36 = call i32 @wait(i32* null)
%37 = call i32 (...) @getpid()
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.7, i64 0, i64 0), i32 %37)
br label %39
39: ; preds = %35, %29, %27
br label %40
40: ; preds = %39, %22
br label %41
41: ; preds = %40
br i1 true, label %9, label %42
42: ; preds = %17, %41
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
@.str = [18 x i8] c"slvr@slvr-prompt$\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [5 x i8] c"exit\00"
@.str.4 = [35 x i8] c"Je suis le slvr-prompt num\C3\A9ro %d\0A\00"
@.str.5 = [25 x i8] c"Probleme : echec du fork\00"
@.str.6 = [31 x i8] c"L'enfant num\C3\A9ro %d est n\C3\A9 !\0A\00"
@.str.7 = [43 x i8] c"Le slvr-prompt num\C3\A9ro %d est de retour !\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%7 = call i32 @bcmp(i8* dereferenceable(5) %4, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 5)
%8 = icmp eq i32 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %2
%10 = bitcast [1024 x i8]* %3 to i32*
br label %12
11: ; preds = %30, %2
ret i32 0
12: ; preds = %9, %30
%13 = load i32, i32* %10
%14 = icmp eq i32 %13, 4475216
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = call i32 (...) @getpid()
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i32 %16)
br label %30
18: ; preds = %12
%19 = call i32 (...) @fork()
switch i32 %19, label %26 [
i32 -1, label %20
i32 0, label %22
]
20: ; preds = %18
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
br label %30
22: ; preds = %18
%23 = call i32 @execlp(i8* %4, i8* %4, i32* null)
%24 = call i32 (...) @getpid()
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i32 %24)
br label %30
26: ; preds = %18
%27 = call i32 @wait(i32* null)
%28 = call i32 (...) @getpid()
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.7, i64 0, i64 0), i32 %28)
br label %30
30: ; preds = %20, %22, %26, %15
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%32 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%33 = call i32 @bcmp(i8* dereferenceable(5) %4, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 5)
%34 = icmp eq i32 %33, 0
br i1 %34, label %11, label %12
}