#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 uid_t;
struct tms {
  int dummy;
};
typedef int pid_t;
typedef int gid_t;

/* Variables and functions */
int getegid();
int geteuid();
int getgid();
int getpid();
int getppid();
int getuid();
int /*<<< orphan*/ printf(char *, int, ...);
int /*<<< orphan*/ setuid(int);
int times(struct tms *);
int main(int argc, char **argv) {
  struct tms *buf;
  int t1 = times(buf);
  pid_t pid = getpid();
  pid_t ppid = getppid();
  uid_t uid = getuid();
  uid_t euid = geteuid();
  gid_t gid = getgid();
  gid_t egid = getegid();
  printf("El pid del proceso es: %d\nEl pid del proceso padre es: %d\n", pid,
         ppid);
  printf("\nEl uid del usuario es: %d\nEl euid del usuario efectivo es: %d\n",
         uid, euid);
  printf("\nEl gid del grupo usuario es: %d\nEl gid del grupo del usuario "
         "efectivo es: %d\n",
         gid, egid);
  setuid((uid_t)1000);
  pid = getpid();
  ppid = getppid();
  uid = getuid();
  euid = geteuid();
  gid = getgid();
  egid = getegid();
  printf("\nEl pid del proceso es: %d\nEl pid del proceso padre es: %d\n", pid,
         ppid);
  printf("\nEl uid del usuario es: %d\nEl euid del usuario efectivo es: %d\n",
         uid, euid);
  printf("\nEl gid del grupo usuario es: %d\nEl gid del grupo del usuario "
         "efectivo es: %d\n",
         gid, egid);
  int t2 = (int)times(buf);
  printf("El tiempo de ejecucion ha sido %d\n", t2 - t1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
call   1090 <times@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x20(%rbp)
mov    $0x0,%al
call   10a0 <getppid@plt>
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1040 <getuid@plt>
mov    %eax,-0x28(%rbp)
mov    $0x0,%al
call   1060 <geteuid@plt>
mov    %eax,-0x2c(%rbp)
mov    $0x0,%al
call   1070 <getgid@plt>
mov    %eax,-0x30(%rbp)
mov    $0x0,%al
call   1080 <getegid@plt>
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%esi
mov    -0x24(%rbp),%edx
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%esi
mov    -0x2c(%rbp),%edx
lea    0xdf1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x30(%rbp),%esi
mov    -0x34(%rbp),%edx
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x3e8,%edi
call   10b0 <setuid@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x20(%rbp)
mov    $0x0,%al
call   10a0 <getppid@plt>
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1040 <getuid@plt>
mov    %eax,-0x28(%rbp)
mov    $0x0,%al
call   1060 <geteuid@plt>
mov    %eax,-0x2c(%rbp)
mov    $0x0,%al
call   1070 <getgid@plt>
mov    %eax,-0x30(%rbp)
mov    $0x0,%al
call   1080 <getegid@plt>
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%esi
mov    -0x24(%rbp),%edx
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%esi
mov    -0x2c(%rbp),%edx
lea    0xd6f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x30(%rbp),%esi
mov    -0x34(%rbp),%edx
lea    0xd9b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1090 <times@plt>
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%esi
sub    -0x1c(%rbp),%esi
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
call   1090 <times@plt>
mov    %eax,0x4(%rsp)
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%r15d
xor    %eax,%eax
call   10a0 <getppid@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1040 <getuid@plt>
mov    %eax,%r12d
xor    %eax,%eax
call   1060 <geteuid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1070 <getgid@plt>
mov    %eax,%r13d
xor    %eax,%eax
call   1080 <getegid@plt>
mov    %eax,%r14d
lea    0xeab(%rip),%rdi
mov    %r15d,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe08(%rip),%rdi
mov    %r12d,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe35(%rip),%rdi
mov    %r13d,%esi
mov    %r14d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x3e8,%edi
call   10b0 <setuid@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%r14d
xor    %eax,%eax
call   10a0 <getppid@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1040 <getuid@plt>
mov    %eax,%r13d
xor    %eax,%eax
call   1060 <geteuid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1070 <getgid@plt>
mov    %eax,%r15d
xor    %eax,%eax
call   1080 <getegid@plt>
mov    %eax,%r12d
lea    0xe2c(%rip),%rdi
mov    %r14d,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xd8a(%rip),%rdi
mov    %r13d,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xdb7(%rip),%rdi
mov    %r15d,%esi
mov    %r12d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
call   1090 <times@plt>
sub    0x4(%rsp),%eax
lea    0xe25(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tms = type { i32 }
@.str = [59 x i8] c"El pid del proceso es: %d\0AEl pid del proceso padre es: %d\0A\00"
@.str.1 = [64 x i8] c"\0AEl uid del usuario es: %d\0AEl euid del usuario efectivo es: %d\0A\00"
@.str.2 = [79 x i8] c"\0AEl gid del grupo usuario es: %d\0AEl gid del grupo del usuario efectivo es: %d\0A\00"
@.str.3 = [60 x i8] c"\0AEl pid del proceso es: %d\0AEl pid del proceso padre es: %d\0A\00"
@.str.4 = [35 x i8] c"El tiempo de ejecucion ha sido %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.tms*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load %struct.tms*, %struct.tms** %6
%16 = call i32 @times(%struct.tms* %15)
store i32 %16, i32* %7
%17 = call i32 (...) @getpid()
store i32 %17, i32* %8
%18 = call i32 (...) @getppid()
store i32 %18, i32* %9
%19 = call i32 (...) @getuid()
store i32 %19, i32* %10
%20 = call i32 (...) @geteuid()
store i32 %20, i32* %11
%21 = call i32 (...) @getgid()
store i32 %21, i32* %12
%22 = call i32 (...) @getegid()
store i32 %22, i32* %13
%23 = load i32, i32* %8
%24 = load i32, i32* %9
%25 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), i32 %23, i32 %24)
%26 = load i32, i32* %10
%27 = load i32, i32* %11
%28 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.1, i64 0, i64 0), i32 %26, i32 %27)
%29 = load i32, i32* %12
%30 = load i32, i32* %13
%31 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str.2, i64 0, i64 0), i32 %29, i32 %30)
%32 = call i32 @setuid(i32 1000)
%33 = call i32 (...) @getpid()
store i32 %33, i32* %8
%34 = call i32 (...) @getppid()
store i32 %34, i32* %9
%35 = call i32 (...) @getuid()
store i32 %35, i32* %10
%36 = call i32 (...) @geteuid()
store i32 %36, i32* %11
%37 = call i32 (...) @getgid()
store i32 %37, i32* %12
%38 = call i32 (...) @getegid()
store i32 %38, i32* %13
%39 = load i32, i32* %8
%40 = load i32, i32* %9
%41 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.3, i64 0, i64 0), i32 %39, i32 %40)
%42 = load i32, i32* %10
%43 = load i32, i32* %11
%44 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.1, i64 0, i64 0), i32 %42, i32 %43)
%45 = load i32, i32* %12
%46 = load i32, i32* %13
%47 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str.2, i64 0, i64 0), i32 %45, i32 %46)
%48 = load %struct.tms*, %struct.tms** %6
%49 = call i32 @times(%struct.tms* %48)
store i32 %49, i32* %14
%50 = load i32, i32* %14
%51 = load i32, i32* %7
%52 = sub nsw i32 %50, %51
%53 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i32 %52)
ret i32 0
}

LLVM IR (-O2):
%struct.tms = type { i32 }
@.str = [59 x i8] c"El pid del proceso es: %d\0AEl pid del proceso padre es: %d\0A\00"
@.str.1 = [64 x i8] c"\0AEl uid del usuario es: %d\0AEl euid del usuario efectivo es: %d\0A\00"
@.str.2 = [79 x i8] c"\0AEl gid del grupo usuario es: %d\0AEl gid del grupo del usuario efectivo es: %d\0A\00"
@.str.3 = [60 x i8] c"\0AEl pid del proceso es: %d\0AEl pid del proceso padre es: %d\0A\00"
@.str.4 = [35 x i8] c"El tiempo de ejecucion ha sido %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @times(%struct.tms* undef)
%4 = tail call i32 (...) @getpid()
%5 = tail call i32 (...) @getppid()
%6 = tail call i32 (...) @getuid()
%7 = tail call i32 (...) @geteuid()
%8 = tail call i32 (...) @getgid()
%9 = tail call i32 (...) @getegid()
%10 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), i32 %4, i32 %5)
%11 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.1, i64 0, i64 0), i32 %6, i32 %7)
%12 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str.2, i64 0, i64 0), i32 %8, i32 %9)
%13 = tail call i32 @setuid(i32 1000)
%14 = tail call i32 (...) @getpid()
%15 = tail call i32 (...) @getppid()
%16 = tail call i32 (...) @getuid()
%17 = tail call i32 (...) @geteuid()
%18 = tail call i32 (...) @getgid()
%19 = tail call i32 (...) @getegid()
%20 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.3, i64 0, i64 0), i32 %14, i32 %15)
%21 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.1, i64 0, i64 0), i32 %16, i32 %17)
%22 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str.2, i64 0, i64 0), i32 %18, i32 %19)
%23 = tail call i32 @times(%struct.tms* undef)
%24 = sub nsw i32 %23, %3
%25 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i32 %24)
ret i32 0
}