#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 spwd {
  char *sp_namp;
  char *sp_pwdp;
  char *sp_lstchg;
  char *sp_min;
  char *sp_max;
  char *sp_warn;
  char *sp_inact;
  char *sp_expire;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ endspent();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
struct spwd *getspent();
scalar_t__ getuid();
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int main(void) {
  uid_t my_uid = getuid();
  struct spwd *sp;
  if (my_uid != 0) {
    fprintf(stderr, "Ops! Only root can read shadow password file.!\n");
    exit(EXIT_FAILURE);
  }
  while ((sp = getspent()) != NULL) {
    printf("     user name: %s\n", sp->sp_namp);
    printf("encrypted pass: %s\n", sp->sp_pwdp);
    printf("  last changes: %ld\n", sp->sp_lstchg);
    printf("           min: %ld\n", sp->sp_min);
    printf("           max: %ld\n", sp->sp_max);
    printf("          warn: %ld\n", sp->sp_warn);
    printf("         inact: %ld\n", sp->sp_inact);
    printf("        expire: %ld\n\n", sp->sp_expire);
  }
  endspent();
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <getuid@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11a8 <main+0x48>
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
lea    0xe6b(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    11ad <main+0x4d>
mov    $0x0,%al
call   1070 <getspent@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1266 <main+0x106>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    0xe60(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe60(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xe60(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rax
mov    0x18(%rax),%rsi
lea    0xe61(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rax
mov    0x20(%rax),%rsi
lea    0xe62(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rax
mov    0x28(%rax),%rsi
lea    0xe63(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rax
mov    0x30(%rax),%rsi
lea    0xe64(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rax
mov    0x38(%rax),%rsi
lea    0xe65(%rip),%rdi
call   1050 <printf@plt>
jmp    11ad <main+0x4d>
mov    $0x0,%al
call   1030 <endspent@plt>
mov    0x2d5c(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1040 <getuid@plt>
test   %rax,%rax
jne    1259 <main+0xf9>
xor    %eax,%eax
call   1070 <getspent@plt>
test   %rax,%rax
je     123a <main+0xda>
mov    %rax,%r15
lea    0xed8(%rip),%r13
lea    0xee6(%rip),%rbx
lea    0xef4(%rip),%rbp
lea    0xf02(%rip),%r14
lea    0xf10(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r15),%rsi
lea    0xe66(%rip),%rdi
call   1050 <printf@plt>
mov    0x8(%r15),%rsi
lea    0xe6a(%rip),%rdi
call   1050 <printf@plt>
mov    0x10(%r15),%rsi
lea    0xe6e(%rip),%rdi
call   1050 <printf@plt>
mov    0x18(%r15),%rsi
mov    %r13,%rdi
call   1050 <printf@plt>
mov    0x20(%r15),%rsi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x28(%r15),%rsi
mov    %rbp,%rdi
call   1050 <printf@plt>
mov    0x30(%r15),%rsi
mov    %r14,%rdi
call   1050 <printf@plt>
mov    0x38(%r15),%rsi
mov    %r12,%rdi
call   1050 <printf@plt>
xor    %eax,%eax
call   1070 <getspent@plt>
mov    %rax,%r15
test   %rax,%rax
jne    11c0 <main+0x60>
xor    %eax,%eax
call   1030 <endspent@plt>
mov    0x2d88(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
lea    0xd97(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d63(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.spwd = type { i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8* }
@stderr = global i32 0
@.str = [48 x i8] c"Ops! Only root can read shadow password file.!\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [20 x i8] c" user name: %s\0A\00"
@.str.2 = [20 x i8] c"encrypted pass: %s\0A\00"
@.str.3 = [21 x i8] c" last changes: %ld\0A\00"
@.str.4 = [21 x i8] c" min: %ld\0A\00"
@.str.5 = [21 x i8] c" max: %ld\0A\00"
@.str.6 = [21 x i8] c" warn: %ld\0A\00"
@.str.7 = [21 x i8] c" inact: %ld\0A\00"
@.str.8 = [22 x i8] c" expire: %ld\0A\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca %struct.spwd*
store i32 0, i32* %1
%4 = call i64 (...) @getuid()
store i64 %4, i64* %2
%5 = load i64, i64* %2
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %0
%8 = load i32, i32* @stderr
%9 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @EXIT_FAILURE
%11 = call i32 @exit(i32 %10)
unreachable
12: ; preds = %0
br label %13
13: ; preds = %16, %12
%14 = call %struct.spwd* (...) @getspent()
store %struct.spwd* %14, %struct.spwd** %3
%15 = icmp ne %struct.spwd* %14, null
br i1 %15, label %16, label %49
16: ; preds = %13
%17 = load %struct.spwd*, %struct.spwd** %3
%18 = getelementptr inbounds %struct.spwd, %struct.spwd* %17, i32 0, i32 0
%19 = load i8*, i8** %18
%20 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = load %struct.spwd*, %struct.spwd** %3
%22 = getelementptr inbounds %struct.spwd, %struct.spwd* %21, i32 0, i32 1
%23 = load i8*, i8** %22
%24 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %23)
%25 = load %struct.spwd*, %struct.spwd** %3
%26 = getelementptr inbounds %struct.spwd, %struct.spwd* %25, i32 0, i32 2
%27 = load i8*, i8** %26
%28 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %27)
%29 = load %struct.spwd*, %struct.spwd** %3
%30 = getelementptr inbounds %struct.spwd, %struct.spwd* %29, i32 0, i32 3
%31 = load i8*, i8** %30
%32 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %31)
%33 = load %struct.spwd*, %struct.spwd** %3
%34 = getelementptr inbounds %struct.spwd, %struct.spwd* %33, i32 0, i32 4
%35 = load i8*, i8** %34
%36 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i8* %35)
%37 = load %struct.spwd*, %struct.spwd** %3
%38 = getelementptr inbounds %struct.spwd, %struct.spwd* %37, i32 0, i32 5
%39 = load i8*, i8** %38
%40 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i8* %39)
%41 = load %struct.spwd*, %struct.spwd** %3
%42 = getelementptr inbounds %struct.spwd, %struct.spwd* %41, i32 0, i32 6
%43 = load i8*, i8** %42
%44 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0), i8* %43)
%45 = load %struct.spwd*, %struct.spwd** %3
%46 = getelementptr inbounds %struct.spwd, %struct.spwd* %45, i32 0, i32 7
%47 = load i8*, i8** %46
%48 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0), i8* %47)
br label %13
49: ; preds = %13
%50 = call i32 (...) @endspent()
%51 = load i32, i32* @EXIT_SUCCESS
ret i32 %51
}

LLVM IR (-O2):
%struct.spwd = type { i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8* }
@stderr = global i32 0
@.str = [48 x i8] c"Ops! Only root can read shadow password file.!\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [20 x i8] c" user name: %s\0A\00"
@.str.2 = [20 x i8] c"encrypted pass: %s\0A\00"
@.str.3 = [21 x i8] c" last changes: %ld\0A\00"
@.str.4 = [21 x i8] c" min: %ld\0A\00"
@.str.5 = [21 x i8] c" max: %ld\0A\00"
@.str.6 = [21 x i8] c" warn: %ld\0A\00"
@.str.7 = [21 x i8] c" inact: %ld\0A\00"
@.str.8 = [22 x i8] c" expire: %ld\0A\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = tail call i64 (...) @getuid()
%2 = icmp eq i64 %1, 0
br i1 %2, label %3, label %6
3: ; preds = %0
%4 = tail call %struct.spwd* (...) @getspent()
%5 = icmp eq %struct.spwd* %4, null
br i1 %5, label %39, label %11
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %3, %11
%12 = phi %struct.spwd* [ %37, %11 ], [ %4, %3 ]
%13 = getelementptr inbounds %struct.spwd, %struct.spwd* %12, i64 0, i32 0
%14 = load i8*, i8** %13
%15 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = getelementptr inbounds %struct.spwd, %struct.spwd* %12, i64 0, i32 1
%17 = load i8*, i8** %16
%18 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %17)
%19 = getelementptr inbounds %struct.spwd, %struct.spwd* %12, i64 0, i32 2
%20 = load i8*, i8** %19
%21 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %20)
%22 = getelementptr inbounds %struct.spwd, %struct.spwd* %12, i64 0, i32 3
%23 = load i8*, i8** %22
%24 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %23)
%25 = getelementptr inbounds %struct.spwd, %struct.spwd* %12, i64 0, i32 4
%26 = load i8*, i8** %25
%27 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i8* %26)
%28 = getelementptr inbounds %struct.spwd, %struct.spwd* %12, i64 0, i32 5
%29 = load i8*, i8** %28
%30 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i8* %29)
%31 = getelementptr inbounds %struct.spwd, %struct.spwd* %12, i64 0, i32 6
%32 = load i8*, i8** %31
%33 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0), i8* %32)
%34 = getelementptr inbounds %struct.spwd, %struct.spwd* %12, i64 0, i32 7
%35 = load i8*, i8** %34
%36 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0), i8* %35)
%37 = tail call %struct.spwd* (...) @getspent()
%38 = icmp eq %struct.spwd* %37, null
br i1 %38, label %39, label %11
39: ; preds = %11, %3
%40 = tail call i32 (...) @endspent()
%41 = load i32, i32* @EXIT_SUCCESS
ret i32 %41
}