#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__ uid_t;
struct utsname {
  char *sysname;
  char *release;
  char *version;
  char *machine;
};
typedef scalar_t__ gid_t;

/* Variables and functions */
scalar_t__ getegid();
scalar_t__ geteuid();
int getpid();
int getppid();
int /*<<< orphan*/ printf(char *, ...);
int system(char *);
int /*<<< orphan*/ uname(struct utsname *);
int main() {
  int pid = getpid();
  int parent_pid = getppid();
  uid_t uid = geteuid();
  gid_t gid = getegid();
  struct utsname u;
  uname(&u);
  printf("Factoid #1: This process has an id of %d\n", pid);
  printf("Factoid #2: This process has a parent with an id of %d\n",
         parent_pid);
  int ret_val = system("echo");
  printf("Factoid #3: We just ran 'echo' through a system call, and the return "
         "value was: %d\n",
         ret_val);
  printf("Factoid #4: Your user id is %d and your group id is %d\n", (int)uid,
         (int)gid);
  printf("Factoid #5: The system you are using is %s release %s (version %s) "
         "on an %s\n",
         u.sysname, u.release, u.version, u.machine);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1090 <getppid@plt>
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1070 <geteuid@plt>
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1080 <getegid@plt>
mov    %rax,-0x20(%rbp)
lea    -0x40(%rbp),%rdi
call   1060 <uname@plt>
mov    -0x8(%rbp),%esi
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xc(%rbp),%esi
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe87(%rip),%rdi
call   1040 <system@plt>
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%esi
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %eax,%esi
mov    -0x20(%rbp),%rax
mov    %eax,%edx
lea    0xeb4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x40(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x28(%rbp),%r8
lea    0xece(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1090 <getppid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1070 <geteuid@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1080 <getegid@plt>
mov    %rax,%r15
lea    0x8(%rsp),%rdi
call   1060 <uname@plt>
lea    0xe4f(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe69(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe91(%rip),%rdi
call   1040 <system@plt>
lea    0xe8a(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xece(%rip),%rdi
mov    %r14d,%esi
mov    %r15d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rsp),%rsi
mov    0x10(%rsp),%rdx
mov    0x18(%rsp),%rcx
mov    0x20(%rsp),%r8
lea    0xede(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.utsname = type { i8*, i8*, i8*, i8* }
@.str = [42 x i8] c"Factoid: This process has an id of %d\0A\00"
@.str.1 = [56 x i8] c"Factoid: This process has a parent with an id of %d\0A\00"
@.str.2 = [5 x i8] c"echo\00"
@.str.3 = [84 x i8] c"Factoid: We just ran 'echo' through a system call, and the return value was: %d\0A\00"
@.str.4 = [56 x i8] c"Factoid: Your user id is %d and your group id is %d\0A\00"
@.str.5 = [77 x i8] c"Factoid: The system you are using is %s release %s (version %s) on an %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i64
%5 = alloca i64
%6 = alloca %struct.utsname
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32 (...) @getpid()
store i32 %8, i32* %2
%9 = call i32 (...) @getppid()
store i32 %9, i32* %3
%10 = call i64 (...) @geteuid()
store i64 %10, i64* %4
%11 = call i64 (...) @getegid()
store i64 %11, i64* %5
%12 = call i32 @uname(%struct.utsname* %6)
%13 = load i32, i32* %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = load i32, i32* %3
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = call i32 @system(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i32 %17, i32* %7
%18 = load i32, i32* %7
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str.3, i64 0, i64 0), i32 %18)
%20 = load i64, i64* %4
%21 = trunc i64 %20 to i32
%22 = load i64, i64* %5
%23 = trunc i64 %22 to i32
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.4, i64 0, i64 0), i32 %21, i32 %23)
%25 = getelementptr inbounds %struct.utsname, %struct.utsname* %6, i32 0, i32 0
%26 = load i8*, i8** %25
%27 = getelementptr inbounds %struct.utsname, %struct.utsname* %6, i32 0, i32 1
%28 = load i8*, i8** %27
%29 = getelementptr inbounds %struct.utsname, %struct.utsname* %6, i32 0, i32 2
%30 = load i8*, i8** %29
%31 = getelementptr inbounds %struct.utsname, %struct.utsname* %6, i32 0, i32 3
%32 = load i8*, i8** %31
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.5, i64 0, i64 0), i8* %26, i8* %28, i8* %30, i8* %32)
ret i32 0
}

LLVM IR (-O2):
%struct.utsname = type { i8*, i8*, i8*, i8* }
@.str = [42 x i8] c"Factoid: This process has an id of %d\0A\00"
@.str.1 = [56 x i8] c"Factoid: This process has a parent with an id of %d\0A\00"
@.str.2 = [5 x i8] c"echo\00"
@.str.3 = [84 x i8] c"Factoid: We just ran 'echo' through a system call, and the return value was: %d\0A\00"
@.str.4 = [56 x i8] c"Factoid: Your user id is %d and your group id is %d\0A\00"
@.str.5 = [77 x i8] c"Factoid: The system you are using is %s release %s (version %s) on an %s\0A\00"
define i32 @main() {
%1 = alloca %struct.utsname
%2 = tail call i32 (...) @getpid()
%3 = tail call i32 (...) @getppid()
%4 = tail call i64 (...) @geteuid()
%5 = tail call i64 (...) @getegid()
%6 = bitcast %struct.utsname* %1 to i8*
%7 = call i32 @uname(%struct.utsname* %1)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %2)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i32 %3)
%10 = tail call i32 @system(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([84 x i8], [84 x i8]* @.str.3, i64 0, i64 0), i32 %10)
%12 = trunc i64 %4 to i32
%13 = trunc i64 %5 to i32
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str.4, i64 0, i64 0), i32 %12, i32 %13)
%15 = getelementptr inbounds %struct.utsname, %struct.utsname* %1, i64 0, i32 0
%16 = load i8*, i8** %15
%17 = getelementptr inbounds %struct.utsname, %struct.utsname* %1, i64 0, i32 1
%18 = load i8*, i8** %17
%19 = getelementptr inbounds %struct.utsname, %struct.utsname* %1, i64 0, i32 2
%20 = load i8*, i8** %19
%21 = getelementptr inbounds %struct.utsname, %struct.utsname* %1, i64 0, i32 3
%22 = load i8*, i8** %21
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([77 x i8], [77 x i8]* @.str.5, i64 0, i64 0), i8* %16, i8* %18, i8* %20, i8* %22)
ret i32 0
}