#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 scalar_t__ pid_t;

/* Variables and functions */
scalar_t__ fork();
scalar_t__ getpid();
scalar_t__ getppid();
int /*<<< orphan*/ printf(char *, ...);
void *funkcja(void *unused) {
  printf("Start funkcji z watku\n");
  pid_t child_pid, parent_pid;
  if (child_pid = fork()) {
    printf("Jestem rodzicem procesu %d! Moje PID to %d\n", (int)child_pid,
           (int)getpid());
  } else {
    child_pid = getpid();
    parent_pid = getppid();
    printf("Jestem %d, a moj rodzic to %d\n", (int)child_pid, (int)parent_pid);
  }
}


x86 assembly (clang, -O0):
<funkcja>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <fork@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1195 <funkcja+0x55>
mov    -0x18(%rbp),%rax
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x24(%rbp),%esi
mov    %eax,%edx
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11c5 <funkcja+0x85>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1050 <getppid@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %eax,%esi
mov    -0x20(%rbp),%rax
mov    %eax,%edx
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<funkcja>:
push   %rbx
lea    0xef3(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
je     117c <funkcja+0x2c>
mov    %rax,%rbx
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe86(%rip),%rdi
jmp    1194 <funkcja+0x44>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1060 <getppid@plt>
lea    0xe98(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
pop    %rbx
ret

LLVM IR (-O0):
@.str = [23 x i8] c"Start funkcji z watku\0A\00"
@.str.1 = [44 x i8] c"Jestem rodzicem procesu %d! Moje PID to %d\0A\00"
@.str.2 = [31 x i8] c"Jestem %d, a moj rodzic to %d\0A\00"
define i8* @funkcja(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
store i8* %0, i8** %3
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%7 = call i64 (...) @fork()
store i64 %7, i64* %4
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %15
9: ; preds = %1
%10 = load i64, i64* %4
%11 = trunc i64 %10 to i32
%12 = call i64 (...) @getpid()
%13 = trunc i64 %12 to i32
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i32 %11, i32 %13)
br label %23
15: ; preds = %1
%16 = call i64 (...) @getpid()
store i64 %16, i64* %4
%17 = call i64 (...) @getppid()
store i64 %17, i64* %5
%18 = load i64, i64* %4
%19 = trunc i64 %18 to i32
%20 = load i64, i64* %5
%21 = trunc i64 %20 to i32
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %19, i32 %21)
br label %23
23: ; preds = %15, %9
%24 = load i8*, i8** %2
ret i8* %24
}

LLVM IR (-O2):
@.str.1 = [44 x i8] c"Jestem rodzicem procesu %d! Moje PID to %d\0A\00"
@.str.2 = [31 x i8] c"Jestem %d, a moj rodzic to %d\0A\00"
@str = [22 x i8] c"Start funkcji z watku\00"
define noalias i8* @funkcja(i8* nocapture readnone %0) {
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%3 = tail call i64 (...) @fork()
%4 = icmp eq i64 %3, 0
br i1 %4, label %10, label %5
5: ; preds = %1
%6 = trunc i64 %3 to i32
%7 = tail call i64 (...) @getpid()
%8 = trunc i64 %7 to i32
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i32 %6, i32 %8)
br label %16
10: ; preds = %1
%11 = tail call i64 (...) @getpid()
%12 = tail call i64 (...) @getppid()
%13 = trunc i64 %11 to i32
%14 = trunc i64 %12 to i32
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %13, i32 %14)
br label %16
16: ; preds = %10, %5
ret i8* undef
}