#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 */
#define EAGAIN 129
#define ENOMEM 128
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
char *strerror(int);
void err_fork(int err) {
  fprintf(stderr, "error: fork(2) system call failed\n");
  switch (err) {
  case EAGAIN:
    fprintf(stderr, "       fork cannot allocate sufficient memory to copy the "
                    "parent's page\n");
    fprintf(stderr,
            "       tables and allocate a task structure for the child.\n");
    break;
  case ENOMEM:
    fprintf(stderr, "       fork failed to allocate the necessary kernel "
                    "structures because\n");
    fprintf(stderr, "       memory is tight.\n");
    break;
  }
  fprintf(stderr, "       errno is: %d\n", err);
  ;
  fprintf(stderr, "       %s\n", strerror(err));
  ;
  fflush(stderr);
}


x86 assembly (clang, -O0):
<err_fork>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e9e(%rip),%rax
mov    (%rax),%edi
lea    0xeb5(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
sub    $0x80,%eax
je     11ae <err_fork+0x7e>
jmp    1168 <err_fork+0x38>
mov    -0x8(%rbp),%eax
sub    $0x81,%eax
jne    11dc <err_fork+0xac>
jmp    117b <err_fork+0x4b>
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
lea    0xe98(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
lea    0xeca(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    11dc <err_fork+0xac>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
lea    0xeea(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
lea    0xf1b(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xf1a(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2de3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <strerror@plt>
mov    -0xc(%rbp),%edi
mov    %rax,%rdx
lea    0xf07(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2dbb(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<err_fork>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
mov    0x2ea0(%rip),%r15
mov    (%r15),%edi
lea    0xeb6(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
cmp    $0x81,%ebx
je     1171 <err_fork+0x41>
cmp    $0x80,%ebx
jne    1196 <err_fork+0x66>
lea    0xf88(%rip),%r14
lea    0xf39(%rip),%rsi
jmp    117f <err_fork+0x4f>
lea    0xef4(%rip),%r14
lea    0xea4(%rip),%rsi
mov    (%r15),%edi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    (%r15),%edi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    (%r15),%edi
lea    0xf69(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    (%r15),%ebp
mov    %ebx,%edi
call   1050 <strerror@plt>
lea    0xf64(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    (%r15),%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fflush@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [35 x i8] c"error: fork(2) system call failed\0A\00"
@.str.1 = [73 x i8] c" fork cannot allocate sufficient memory to copy the parent's page\0A\00"
@.str.2 = [60 x i8] c" tables and allocate a task structure for the child.\0A\00"
@.str.3 = [72 x i8] c" fork failed to allocate the necessary kernel structures because\0A\00"
@.str.4 = [25 x i8] c" memory is tight.\0A\00"
@.str.5 = [21 x i8] c" errno is: %d\0A\00"
@.str.6 = [11 x i8] c" %s\0A\00"
define void @err_fork(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* @stderr
%4 = call i32 (i32, i8*, ...) @fprintf(i32 %3, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%5 = load i32, i32* %2
switch i32 %5, label %16 [
i32 129, label %6
i32 128, label %11
]
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.1, i64 0, i64 0))
%9 = load i32, i32* @stderr
%10 = call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.2, i64 0, i64 0))
br label %16
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.3, i64 0, i64 0))
%14 = load i32, i32* @stderr
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
br label %16
16: ; preds = %1, %11, %6
%17 = load i32, i32* @stderr
%18 = load i32, i32* %2
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 %18)
%20 = load i32, i32* @stderr
%21 = load i32, i32* %2
%22 = call i8* @strerror(i32 %21)
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8* %22)
%24 = load i32, i32* @stderr
%25 = call i32 @fflush(i32 %24)
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [35 x i8] c"error: fork(2) system call failed\0A\00"
@.str.1 = [73 x i8] c" fork cannot allocate sufficient memory to copy the parent's page\0A\00"
@.str.2 = [60 x i8] c" tables and allocate a task structure for the child.\0A\00"
@.str.3 = [72 x i8] c" fork failed to allocate the necessary kernel structures because\0A\00"
@.str.4 = [25 x i8] c" memory is tight.\0A\00"
@.str.5 = [21 x i8] c" errno is: %d\0A\00"
@.str.6 = [11 x i8] c" %s\0A\00"
define void @err_fork(i32 %0) {
%2 = load i32, i32* @stderr
%3 = tail call i32 (i32, i8*, ...) @fprintf(i32 %2, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
switch i32 %0, label %12 [
i32 129, label %5
i32 128, label %4
]
4: ; preds = %1
br label %5
5: ; preds = %1, %4
%6 = phi i8* [ getelementptr inbounds ([72 x i8], [72 x i8]* @.str.3, i64 0, i64 0), %4 ], [ getelementptr inbounds ([73 x i8], [73 x i8]* @.str.1, i64 0, i64 0), %1 ]
%7 = phi i8* [ getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), %4 ], [ getelementptr inbounds ([60 x i8], [60 x i8]* @.str.2, i64 0, i64 0), %1 ]
%8 = load i32, i32* @stderr
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* %6)
%10 = load i32, i32* @stderr
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* %7)
br label %12
12: ; preds = %5, %1
%13 = load i32, i32* @stderr
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 %0)
%15 = load i32, i32* @stderr
%16 = tail call i8* @strerror(i32 %0)
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8* %16)
%18 = load i32, i32* @stderr
%19 = tail call i32 @fflush(i32 %18)
ret void
}