#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 passwd {
  int /*<<< orphan*/ pw_name;
};

/* Variables and functions */
scalar_t__ errno;
scalar_t__ getpid();
struct passwd *getpwuid(int /*<<< orphan*/);
int /*<<< orphan*/ getuid();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, long, int /*<<< orphan*/);
int system(char *);
int main(int argc, char *argv[]) {
  struct passwd *pw = NULL;
  char cmd[256];
  int rc;
  long pid = (long)getpid();
  if ((pw = getpwuid(getuid())) == NULL) {
    perror("getpwuid()");
    return 0;
  }
  sprintf(cmd, "ps f | mail -s 'PID %ld' %s", pid, pw->pw_name);
  errno = 0;
  rc = system(cmd);
  if (rc == 127 && errno != 0) {
    perror(cmd);
  } else if (rc == -1) {
    perror(cmd);
  } else {
    printf("command '%s'\n returned code %d\n", cmd, rc);
    printf("check your mail\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %rax,-0x130(%rbp)
mov    $0x0,%al
call   1050 <getuid@plt>
mov    %eax,%edi
call   1040 <getpwuid@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11d3 <main+0x63>
lea    0xe3e(%rip),%rdi
call   1080 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    1295 <main+0x125>
lea    -0x120(%rbp),%rdi
mov    -0x130(%rbp),%rdx
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
lea    0xe1d(%rip),%rsi
call   1090 <sprintf@plt>
mov    0x2de6(%rip),%rax
movq   $0x0,(%rax)
lea    -0x120(%rbp),%rdi
call   1060 <system@plt>
mov    %eax,-0x124(%rbp)
cmpl   $0x7f,-0x124(%rbp)
jne    1242 <main+0xd2>
mov    0x2db9(%rip),%rax
cmpq   $0x0,(%rax)
je     1242 <main+0xd2>
lea    -0x120(%rbp),%rdi
call   1080 <perror@plt>
jmp    128e <main+0x11e>
cmpl   $0xffffffff,-0x124(%rbp)
jne    1260 <main+0xf0>
lea    -0x120(%rbp),%rdi
call   1080 <perror@plt>
jmp    1289 <main+0x119>
lea    -0x120(%rbp),%rsi
mov    -0x124(%rbp),%edx
lea    0xdb3(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xdc5(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    128e <main+0x11e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x108,%rsp
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1060 <getuid@plt>
mov    %eax,%edi
call   1050 <getpwuid@plt>
test   %rax,%rax
je     121a <main+0x9a>
mov    (%rax),%ecx
lea    0xe5b(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
mov    %rbx,%rdx
call   10a0 <sprintf@plt>
mov    0x2e1b(%rip),%rbx
movq   $0x0,(%rbx)
mov    %r14,%rdi
call   1070 <system@plt>
cmp    $0x7f,%eax
jne    11df <main+0x5f>
cmpq   $0x0,(%rbx)
jne    1210 <main+0x90>
cmp    $0xffffffff,%eax
je     1210 <main+0x90>
lea    0xe3c(%rip),%rdi
mov    %rsp,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xe49(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret
mov    %rsp,%rdi
call   1090 <perror@plt>
jmp    1203 <main+0x83>
lea    0xddf(%rip),%rdi
call   1090 <perror@plt>
jmp    1203 <main+0x83>

LLVM IR (-O0):
%struct.passwd = type { i32 }
@.str = [11 x i8] c"getpwuid()\00"
@.str.1 = [28 x i8] c"ps f | mail -s 'PID %ld' %s\00"
@errno = global i64 0
@.str.2 = [32 x i8] c"command '%s'\0A returned code %d\0A\00"
@.str.3 = [17 x i8] c"check your mail\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.passwd*
%7 = alloca [256 x i8]
%8 = alloca i32
%9 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store %struct.passwd* null, %struct.passwd** %6
%10 = call i64 (...) @getpid()
store i64 %10, i64* %9
%11 = call i32 (...) @getuid()
%12 = call %struct.passwd* @getpwuid(i32 %11)
store %struct.passwd* %12, %struct.passwd** %6
%13 = icmp eq %struct.passwd* %12, null
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %46
16: ; preds = %2
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%18 = load i64, i64* %9
%19 = load %struct.passwd*, %struct.passwd** %6
%20 = getelementptr inbounds %struct.passwd, %struct.passwd* %19, i32 0, i32 0
%21 = load i32, i32* %20
%22 = call i32 @sprintf(i8* %17, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i64 %18, i32 %21)
store i64 0, i64* @errno
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%24 = call i32 @system(i8* %23)
store i32 %24, i32* %8
%25 = load i32, i32* %8
%26 = icmp eq i32 %25, 127
br i1 %26, label %27, label %33
27: ; preds = %16
%28 = load i64, i64* @errno
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %27
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%32 = call i32 @perror(i8* %31)
br label %45
33: ; preds = %27, %16
%34 = load i32, i32* %8
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %39
36: ; preds = %33
%37 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%38 = call i32 @perror(i8* %37)
br label %44
39: ; preds = %33
%40 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%41 = load i32, i32* %8
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %40, i32 %41)
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %44
44: ; preds = %39, %36
br label %45
45: ; preds = %44, %30
store i32 0, i32* %3
br label %46
46: ; preds = %45, %14
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
%struct.passwd = type { i32 }
@.str = [11 x i8] c"getpwuid()\00"
@.str.1 = [28 x i8] c"ps f | mail -s 'PID %ld' %s\00"
@errno = global i64 0
@.str.2 = [32 x i8] c"command '%s'\0A returned code %d\0A\00"
@str = [16 x i8] c"check your mail\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = tail call i64 (...) @getpid()
%6 = tail call i32 (...) @getuid()
%7 = tail call %struct.passwd* @getpwuid(i32 %6)
%8 = icmp eq %struct.passwd* %7, null
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %29
11: ; preds = %2
%12 = getelementptr inbounds %struct.passwd, %struct.passwd* %7, i64 0, i32 0
%13 = load i32, i32* %12
%14 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i64 %5, i32 %13)
store i64 0, i64* @errno
%15 = call i32 @system(i8* %4)
%16 = icmp eq i32 %15, 127
%17 = load i64, i64* @errno
%18 = icmp ne i64 %17, 0
%19 = select i1 %16, i1 %18, i1 false
br i1 %19, label %20, label %22
20: ; preds = %11
%21 = call i32 @perror(i8* %4)
br label %29
22: ; preds = %11
%23 = icmp eq i32 %15, -1
br i1 %23, label %24, label %26
24: ; preds = %22
%25 = call i32 @perror(i8* %4)
br label %29
26: ; preds = %22
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %4, i32 %15)
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
br label %29
29: ; preds = %20, %26, %24, %9
ret i32 0
}