#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 */

/* Variables and functions */
int /*<<< orphan*/ clear();
int /*<<< orphan*/ display_motd(char *);
int /*<<< orphan*/ get_time();
char *getenv(char *);
int /*<<< orphan*/ log_entry(char *, char *, char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ sleep(int);
char *strtok(char *, char *);
int main(void) {
  char *ssh_connection;
  char *ssh_tty;
  char *ssh_logname;
  char *delimiter = " ";
  char *ip_address;
  ssh_connection = getenv("SSH_CONNECTION");
  ssh_tty = getenv("SSH_TTY");
  ssh_logname = getenv("LOGNAME");
  ip_address = strtok(ssh_connection, delimiter);
  if (ssh_connection) {
    log_entry(ssh_logname, ssh_tty, ip_address);
    while (1) {
      clear();
      get_time();
      display_motd("/etc/motd");
      sleep(60);
    }
  } else {
    puts("This shell is meant to use only for ssh forward users.");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe6a(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xe61(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
lea    0xe60(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
lea    0xe58(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1220 <main+0xa0>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1060 <log_entry@plt>
mov    $0x0,%al
call   1090 <clear@plt>
mov    $0x0,%al
call   1050 <get_time@plt>
lea    0xe15(%rip),%rdi
call   1080 <display_motd@plt>
mov    $0x3c,%edi
call   10a0 <sleep@plt>
jmp    11f7 <main+0x77>
lea    0xe04(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
lea    0xe76(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
lea    0xe76(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%r14
lea    0xe6f(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%r15
lea    0xe47(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strtok@plt>
test   %rbx,%rbx
je     1202 <main+0x82>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rax,%rdx
call   1060 <log_entry@plt>
lea    0xe46(%rip),%rbx
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1090 <clear@plt>
xor    %eax,%eax
call   1050 <get_time@plt>
mov    %rbx,%rdi
call   1080 <display_motd@plt>
mov    $0x3c,%edi
call   10a0 <sleep@plt>
jmp    11e0 <main+0x60>
lea    0xe22(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
@.str.1 = [15 x i8] c"SSH_CONNECTION\00"
@.str.2 = [8 x i8] c"SSH_TTY\00"
@.str.3 = [8 x i8] c"LOGNAME\00"
@.str.4 = [10 x i8] c"/etc/motd\00"
@.str.5 = [55 x i8] c"This shell is meant to use only for ssh forward users.\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i32 0, i32* %1
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %5
%7 = call i8* @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
store i8* %7, i8** %2
%8 = call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
store i8* %8, i8** %3
%9 = call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
store i8* %9, i8** %4
%10 = load i8*, i8** %2
%11 = load i8*, i8** %5
%12 = call i8* @strtok(i8* %10, i8* %11)
store i8* %12, i8** %6
%13 = load i8*, i8** %2
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %25
15: ; preds = %0
%16 = load i8*, i8** %4
%17 = load i8*, i8** %3
%18 = load i8*, i8** %6
%19 = call i32 @log_entry(i8* %16, i8* %17, i8* %18)
br label %20
20: ; preds = %15, %20
%21 = call i32 (...) @clear()
%22 = call i32 (...) @get_time()
%23 = call i32 @display_motd(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%24 = call i32 @sleep(i32 60)
br label %20
25: ; preds = %0
%26 = call i32 @puts(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.5, i64 0, i64 0))
br label %27
27: ; preds = %25
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
@.str.1 = [15 x i8] c"SSH_CONNECTION\00"
@.str.2 = [8 x i8] c"SSH_TTY\00"
@.str.3 = [8 x i8] c"LOGNAME\00"
@.str.4 = [10 x i8] c"/etc/motd\00"
@.str.5 = [55 x i8] c"This shell is meant to use only for ssh forward users.\00"
define i32 @main() {
%1 = tail call i8* @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%2 = tail call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%3 = tail call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%4 = tail call i8* @strtok(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i8* %1, null
br i1 %5, label %13, label %6
6: ; preds = %0
%7 = tail call i32 @log_entry(i8* %3, i8* %2, i8* %4)
br label %8
8: ; preds = %8, %6
%9 = tail call i32 (...) @clear()
%10 = tail call i32 (...) @get_time()
%11 = tail call i32 @display_motd(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%12 = tail call i32 @sleep(i32 60)
br label %8
13: ; preds = %0
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}