#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 */
struct timeval {
  int /*<<< orphan*/ tv_usec;
  int /*<<< orphan*/ tv_sec;
};
typedef int pid_t;

/* Variables and functions */
int /*<<< orphan*/ getpid();
int /*<<< orphan*/ getppid();
int getsid(int);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int show_sid(pid_t pid) {
  do {
    struct timeval tv;
    gettimeofday(&tv, NULL);
    printf("%ld.%6ld [%d->%d] -- ", tv.tv_sec, tv.tv_usec, getppid(), getpid());
    printf("pid[%d], sid [%d]", pid, getsid(pid));
    printf("\n");
  } while (0);
  return 0;
}


x86 assembly (clang, -O0):
<show_sid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gettimeofday@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1070 <getppid@plt>
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x20(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    %eax,%r8d
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <getsid@plt>
mov    -0x14(%rbp),%esi
mov    %eax,%edx
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_sid>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r14d
mov    %rsp,%rdi
xor    %esi,%esi
call   1070 <gettimeofday@plt>
mov    (%rsp),%r15d
mov    0x4(%rsp),%ebx
xor    %eax,%eax
call   1080 <getppid@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe6d(%rip),%rdi
mov    %ebx,%esi
mov    %r15d,%edx
mov    %ebp,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14d,%edi
call   1060 <getsid@plt>
lea    0xe63(%rip),%rdi
mov    %r14d,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@.str = [22 x i8] c"%ld.%6ld [%d->%d] -- \00"
@.str.1 = [18 x i8] c"pid[%d], sid [%d]\00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @show_sid(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.timeval
store i32 %0, i32* %2
br label %4
4: ; preds = %1
%5 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%7 = load i32, i32* %6
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%9 = load i32, i32* %8
%10 = call i32 (...) @getppid()
%11 = call i32 (...) @getpid()
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %9, i32 %10, i32 %11)
%13 = load i32, i32* %2
%14 = load i32, i32* %2
%15 = call i32 @getsid(i32 %14)
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %13, i32 %15)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %18
18: ; preds = %4
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@.str = [22 x i8] c"%ld.%6ld [%d->%d] -- \00"
@.str.1 = [18 x i8] c"pid[%d], sid [%d]\00"
define i32 @show_sid(i32 %0) {
%2 = alloca %struct.timeval
%3 = bitcast %struct.timeval* %2 to i8*
%4 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%6 = load i32, i32* %5
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%8 = load i32, i32* %7
%9 = tail call i32 (...) @getppid()
%10 = tail call i32 (...) @getpid()
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %8, i32 %9, i32 %10)
%12 = tail call i32 @getsid(i32 %0)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %0, i32 %12)
%14 = tail call i32 @putchar(i32 10)
ret i32 0
}