#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 stat {
  scalar_t__ st_ino;
};
struct passwd {
  char *pw_dir;
  char *pw_name;
  scalar_t__ pw_gid;
  scalar_t__ pw_uid;
};
struct group {
  char *gr_name;
};

/* Variables and functions */
struct group *getgrgid(scalar_t__);
struct passwd *getpwuid(scalar_t__);
scalar_t__ getuid();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stat(char const *, struct stat *);
int userdetails() {
  uid_t user = getuid();
  struct passwd *my_passwd = getpwuid(user);
  struct group *my_group;
  struct stat sb;
  const char *homedir = my_passwd->pw_dir;
  stat(homedir, &sb);
  if (!my_passwd) {
    printf("Couldn't find out about user %d\n", (int)user);
    return 1;
  }
  my_group = getgrgid(my_passwd->pw_gid);
  if (!my_group) {
    printf("Couldn't find out about group %d.\n", (int)my_passwd->pw_gid);
    return 1;
  }
  printf("%d,", (int)(my_passwd->pw_uid));
  printf("%d,", (int)(my_passwd->pw_gid));
  printf("%s,", my_passwd->pw_name);
  printf("%s,", my_group->gr_name);
  printf("%ld", (long)sb.st_ino);
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<userdetails>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    $0x0,%al
call   1040 <getuid@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <getpwuid@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1070 <stat@plt>
cmpq   $0x0,-0x18(%rbp)
jne    11b3 <userdetails+0x63>
mov    -0x10(%rbp),%rax
mov    %eax,%esi
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1275 <userdetails+0x125>
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rdi
call   1060 <getgrgid@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11f3 <userdetails+0xa3>
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rax
mov    %eax,%esi
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1275 <userdetails+0x125>
mov    -0x18(%rbp),%rax
mov    0x18(%rax),%rax
mov    %eax,%esi
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rax
mov    %eax,%esi
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rsi
lea    0xdf3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xddb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<userdetails>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %r14d,%r14d
xor    %eax,%eax
call   1050 <getuid@plt>
mov    %rax,%rdi
call   1040 <getpwuid@plt>
mov    %rax,%rbx
mov    (%rax),%rdi
mov    %rsp,%rsi
call   1080 <stat@plt>
mov    0x10(%rbx),%rdi
call   1070 <getgrgid@plt>
test   %rax,%rax
je     11fa <userdetails+0x9a>
mov    %rax,%rbp
mov    0x18(%rbx),%esi
lea    0xe81(%rip),%r15
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x10(%rbx),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x8(%rbx),%rsi
lea    0xe63(%rip),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x0(%rbp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    (%rsp),%rsi
lea    0xe44(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1211 <userdetails+0xb1>
mov    0x10(%rbx),%esi
lea    0xdfc(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.passwd = type { i8*, i8*, i64, i64 }
%struct.group = type { i8* }
%struct.stat = type { i64 }
@.str = [33 x i8] c"Couldn't find out about user %d\0A\00"
@.str.1 = [35 x i8] c"Couldn't find out about group %d.\0A\00"
@.str.2 = [4 x i8] c"%d,\00"
@.str.3 = [4 x i8] c"%s,\00"
@.str.4 = [4 x i8] c"%ld\00"
@.str.5 = [2 x i8] c"\0A\00"
define i32 @userdetails() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca %struct.passwd*
%4 = alloca %struct.group*
%5 = alloca %struct.stat
%6 = alloca i8*
%7 = call i64 (...) @getuid()
store i64 %7, i64* %2
%8 = load i64, i64* %2
%9 = call %struct.passwd* @getpwuid(i64 %8)
store %struct.passwd* %9, %struct.passwd** %3
%10 = load %struct.passwd*, %struct.passwd** %3
%11 = getelementptr inbounds %struct.passwd, %struct.passwd* %10, i32 0, i32 0
%12 = load i8*, i8** %11
store i8* %12, i8** %6
%13 = load i8*, i8** %6
%14 = call i32 @stat(i8* %13, %struct.stat* %5)
%15 = load %struct.passwd*, %struct.passwd** %3
%16 = icmp ne %struct.passwd* %15, null
br i1 %16, label %21, label %17
17: ; preds = %0
%18 = load i64, i64* %2
%19 = trunc i64 %18 to i32
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %19)
store i32 1, i32* %1
br label %57
21: ; preds = %0
%22 = load %struct.passwd*, %struct.passwd** %3
%23 = getelementptr inbounds %struct.passwd, %struct.passwd* %22, i32 0, i32 2
%24 = load i64, i64* %23
%25 = call %struct.group* @getgrgid(i64 %24)
store %struct.group* %25, %struct.group** %4
%26 = load %struct.group*, %struct.group** %4
%27 = icmp ne %struct.group* %26, null
br i1 %27, label %34, label %28
28: ; preds = %21
%29 = load %struct.passwd*, %struct.passwd** %3
%30 = getelementptr inbounds %struct.passwd, %struct.passwd* %29, i32 0, i32 2
%31 = load i64, i64* %30
%32 = trunc i64 %31 to i32
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 %32)
store i32 1, i32* %1
br label %57
34: ; preds = %21
%35 = load %struct.passwd*, %struct.passwd** %3
%36 = getelementptr inbounds %struct.passwd, %struct.passwd* %35, i32 0, i32 3
%37 = load i64, i64* %36
%38 = trunc i64 %37 to i32
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %38)
%40 = load %struct.passwd*, %struct.passwd** %3
%41 = getelementptr inbounds %struct.passwd, %struct.passwd* %40, i32 0, i32 2
%42 = load i64, i64* %41
%43 = trunc i64 %42 to i32
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %43)
%45 = load %struct.passwd*, %struct.passwd** %3
%46 = getelementptr inbounds %struct.passwd, %struct.passwd* %45, i32 0, i32 1
%47 = load i8*, i8** %46
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %47)
%49 = load %struct.group*, %struct.group** %4
%50 = getelementptr inbounds %struct.group, %struct.group* %49, i32 0, i32 0
%51 = load i8*, i8** %50
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %51)
%53 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%54 = load i64, i64* %53
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i64 %54)
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %1
br label %57
57: ; preds = %34, %28, %17
%58 = load i32, i32* %1
ret i32 %58
}

LLVM IR (-O2):
%struct.stat = type { i64 }
%struct.passwd = type { i8*, i8*, i64, i64 }
%struct.group = type { i8* }
@.str.1 = [35 x i8] c"Couldn't find out about group %d.\0A\00"
@.str.2 = [4 x i8] c"%d,\00"
@.str.3 = [4 x i8] c"%s,\00"
@.str.4 = [4 x i8] c"%ld\00"
define i32 @userdetails() {
%1 = alloca %struct.stat
%2 = tail call i64 (...) @getuid()
%3 = tail call %struct.passwd* @getpwuid(i64 %2)
%4 = bitcast %struct.stat* %1 to i8*
%5 = getelementptr inbounds %struct.passwd, %struct.passwd* %3, i64 0, i32 0
%6 = load i8*, i8** %5
%7 = call i32 @stat(i8* %6, %struct.stat* %1)
%8 = getelementptr inbounds %struct.passwd, %struct.passwd* %3, i64 0, i32 2
%9 = load i64, i64* %8
%10 = tail call %struct.group* @getgrgid(i64 %9)
%11 = icmp eq %struct.group* %10, null
br i1 %11, label %12, label %16
12: ; preds = %0
%13 = load i64, i64* %8
%14 = trunc i64 %13 to i32
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 %14)
br label %34
16: ; preds = %0
%17 = getelementptr inbounds %struct.passwd, %struct.passwd* %3, i64 0, i32 3
%18 = load i64, i64* %17
%19 = trunc i64 %18 to i32
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = load i64, i64* %8
%22 = trunc i64 %21 to i32
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %22)
%24 = getelementptr inbounds %struct.passwd, %struct.passwd* %3, i64 0, i32 1
%25 = load i8*, i8** %24
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %25)
%27 = getelementptr inbounds %struct.group, %struct.group* %10, i64 0, i32 0
%28 = load i8*, i8** %27
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %28)
%30 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
%31 = load i64, i64* %30
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i64 %31)
%33 = tail call i32 @putchar(i32 10)
br label %34
34: ; preds = %16, %12
%35 = phi i32 [ 0, %16 ], [ 1, %12 ]
ret i32 %35
}