#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 /*<<< orphan*/ time_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SIGBUS;
int /*<<< orphan*/ SIGTERM;
char *ctime(int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *, ...);
int /*<<< orphan*/ free(char *);
char *getenv(char *);
int /*<<< orphan*/ getppid();
int /*<<< orphan*/ kill(int /*<<< orphan*/, int /*<<< orphan*/);
char *malloc(int);
scalar_t__ match(char *, char *);
int /*<<< orphan*/ sleep(int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  char *ENV;
  int i;
  FILE *F;
  time_t T;
  time(&T);
  F = fopen("/var/log/ssh_connect.log", "at");
  if (getenv("SSH_CONNECTION") == 0) {
    fprintf(F, " Login from console %s\n", ctime(&T));
    fflush(F);
    fclose(F);
    return -1;
  }
  ENV = malloc(1024 * 16);
  sprintf(ENV, "%s",
          getenv("SSH_CONNECTION") ? getenv("SSH_CONNECTION") : "not set");
  fprintf(F, "Connection from: %s %s", ENV, ctime(&T));
  fflush(F);
  for (i = 1; i < argc; i++) {
    if (match(ENV, argv[i]) == 0)
      return 0;
  }
  fprintf(F, "Try to login from unallowed address %s %s", ENV, ctime(&T));
  fflush(F);
  sleep(0);
  free(ENV);
  fclose(F);
  kill(getppid(), SIGTERM);
  kill(getppid(), SIGBUS);
  kill(0, SIGTERM);
  kill(0, SIGBUS);
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x2c(%rbp),%rdi
call   1090 <time@plt>
lea    0xdfa(%rip),%rdi
lea    0xe0c(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x28(%rbp)
lea    0xdff(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
jne    1270 <main+0x90>
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    -0x2c(%rbp),%rdi
call   1060 <ctime@plt>
mov    -0x38(%rbp),%rdi
mov    %rax,%rdx
lea    0xde0(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   10b0 <fflush@plt>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    140a <main+0x22a>
mov    $0x4000,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    0xd8f(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
je     12b1 <main+0xd1>
lea    0xd79(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x48(%rbp)
jmp    12c1 <main+0xe1>
lea    0xd8b(%rip),%rax
mov    %rax,-0x48(%rbp)
jmp    12c1 <main+0xe1>
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rdx
lea    0xd8f(%rip),%rsi
call   10e0 <sprintf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x50(%rbp)
lea    -0x2c(%rbp),%rdi
call   1060 <ctime@plt>
mov    -0x58(%rbp),%rdi
mov    -0x50(%rbp),%rdx
mov    %rax,%rcx
lea    0xd4b(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   10b0 <fflush@plt>
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1361 <main+0x181>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   10c0 <match@plt>
cmp    $0x0,%rax
jne    134e <main+0x16e>
movl   $0x0,-0x4(%rbp)
jmp    140a <main+0x22a>
jmp    1353 <main+0x173>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1317 <main+0x137>
mov    -0x28(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x60(%rbp)
lea    -0x2c(%rbp),%rdi
call   1060 <ctime@plt>
mov    -0x68(%rbp),%rdi
mov    -0x60(%rbp),%rdx
mov    %rax,%rcx
lea    0xcd6(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   10b0 <fflush@plt>
xor    %edi,%edi
call   1100 <sleep@plt>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
mov    $0x0,%al
call   10f0 <getppid@plt>
mov    %eax,%edi
mov    0x2c1b(%rip),%rax
mov    (%rax),%esi
call   1080 <kill@plt>
mov    $0x0,%al
call   10f0 <getppid@plt>
mov    %eax,%edi
mov    0x2c14(%rip),%rax
mov    (%rax),%esi
call   1080 <kill@plt>
mov    0x2bf6(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
call   1080 <kill@plt>
mov    0x2bf6(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
call   1080 <kill@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r15
mov    %edi,%ebp
lea    0xc(%rsp),%rdi
call   10a0 <time@plt>
lea    0xdfe(%rip),%rdi
lea    0xe10(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,%r14
lea    0xe04(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1337 <main+0x157>
mov    $0x4000,%edi
call   10b0 <malloc@plt>
mov    %rax,%r12
lea    0xde2(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
lea    0xdfa(%rip),%rsi
cmovne %rax,%rsi
mov    %r12,%rdi
call   1050 <strcpy@plt>
lea    0xc(%rsp),%rdi
call   1070 <ctime@plt>
lea    0xde5(%rip),%rsi
mov    %r14,%rdi
mov    %r12,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %r14,%rdi
call   10c0 <fflush@plt>
cmp    $0x2,%ebp
jl     12ae <main+0xce>
mov    %ebp,%ebp
mov    $0x1,%ebx
nopw   0x0(%rax,%rax,1)
mov    (%r15,%rbx,8),%rsi
mov    %r12,%rdi
call   10d0 <match@plt>
test   %rax,%rax
je     136c <main+0x18c>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1290 <main+0xb0>
lea    0xc(%rsp),%rdi
call   1070 <ctime@plt>
lea    0xda3(%rip),%rsi
mov    %r14,%rdi
mov    %r12,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %r14,%rdi
call   10c0 <fflush@plt>
xor    %edi,%edi
call   1100 <sleep@plt>
mov    %r12,%rdi
call   1040 <free@plt>
mov    %r14,%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
call   10f0 <getppid@plt>
mov    0x2ce4(%rip),%rbx
mov    (%rbx),%esi
mov    %eax,%edi
call   1090 <kill@plt>
xor    %eax,%eax
call   10f0 <getppid@plt>
mov    0x2cdd(%rip),%rbp
mov    0x0(%rbp),%esi
mov    %eax,%edi
call   1090 <kill@plt>
mov    (%rbx),%esi
xor    %edi,%edi
call   1090 <kill@plt>
mov    0x0(%rbp),%esi
xor    %edi,%edi
call   1090 <kill@plt>
mov    $0x1,%eax
jmp    136e <main+0x18e>
lea    0xc(%rsp),%rdi
call   1070 <ctime@plt>
lea    0xce3(%rip),%rsi
mov    %r14,%rdi
mov    %rax,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %r14,%rdi
call   10c0 <fflush@plt>
mov    %r14,%rdi
call   1060 <fclose@plt>
mov    $0xffffffff,%eax
jmp    136e <main+0x18e>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"/var/log/ssh_connect.log\00"
@.str.1 = [3 x i8] c"at\00"
@.str.2 = [15 x i8] c"SSH_CONNECTION\00"
@.str.3 = [24 x i8] c" Login from console %s\0A\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [8 x i8] c"not set\00"
@.str.6 = [23 x i8] c"Connection from: %s %s\00"
@.str.7 = [42 x i8] c"Try to login from unallowed address %s %s\00"
@SIGTERM = global i32 0
@SIGBUS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i32 @time(i32* %9)
%11 = call i32* @fopen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %8
%12 = call i8* @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %22
14: ; preds = %2
%15 = load i32*, i32** %8
%16 = call i8* @ctime(i32* %9)
%17 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %15, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %16)
%18 = load i32*, i32** %8
%19 = call i32 @fflush(i32* %18)
%20 = load i32*, i32** %8
%21 = call i32 @fclose(i32* %20)
store i32 -1, i32* %3
br label %79
22: ; preds = %2
%23 = call i8* @malloc(i32 16384)
store i8* %23, i8** %6
%24 = load i8*, i8** %6
%25 = call i8* @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %29
27: ; preds = %22
%28 = call i8* @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %30
29: ; preds = %22
br label %30
30: ; preds = %29, %27
%31 = phi i8* [ %28, %27 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), %29 ]
%32 = call i32 @sprintf(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %31)
%33 = load i32*, i32** %8
%34 = load i8*, i8** %6
%35 = call i8* @ctime(i32* %9)
%36 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %33, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i8* %34, i8* %35)
%37 = load i32*, i32** %8
%38 = call i32 @fflush(i32* %37)
store i32 1, i32* %7
br label %39
39: ; preds = %54, %30
%40 = load i32, i32* %7
%41 = load i32, i32* %4
%42 = icmp slt i32 %40, %41
br i1 %42, label %43, label %57
43: ; preds = %39
%44 = load i8*, i8** %6
%45 = load i8**, i8*** %5
%46 = load i32, i32* %7
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8*, i8** %45, i64 %47
%49 = load i8*, i8** %48
%50 = call i64 @match(i8* %44, i8* %49)
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %53
52: ; preds = %43
store i32 0, i32* %3
br label %79
53: ; preds = %43
br label %54
54: ; preds = %53
%55 = load i32, i32* %7
%56 = add nsw i32 %55, 1
store i32 %56, i32* %7
br label %39
57: ; preds = %39
%58 = load i32*, i32** %8
%59 = load i8*, i8** %6
%60 = call i8* @ctime(i32* %9)
%61 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %58, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0), i8* %59, i8* %60)
%62 = load i32*, i32** %8
%63 = call i32 @fflush(i32* %62)
%64 = call i32 @sleep(i32 0)
%65 = load i8*, i8** %6
%66 = call i32 @free(i8* %65)
%67 = load i32*, i32** %8
%68 = call i32 @fclose(i32* %67)
%69 = call i32 (...) @getppid()
%70 = load i32, i32* @SIGTERM
%71 = call i32 @kill(i32 %69, i32 %70)
%72 = call i32 (...) @getppid()
%73 = load i32, i32* @SIGBUS
%74 = call i32 @kill(i32 %72, i32 %73)
%75 = load i32, i32* @SIGTERM
%76 = call i32 @kill(i32 0, i32 %75)
%77 = load i32, i32* @SIGBUS
%78 = call i32 @kill(i32 0, i32 %77)
store i32 1, i32* %3
br label %79
79: ; preds = %57, %52, %14
%80 = load i32, i32* %3
ret i32 %80
}

LLVM IR (-O2):
@.str = [25 x i8] c"/var/log/ssh_connect.log\00"
@.str.1 = [3 x i8] c"at\00"
@.str.2 = [15 x i8] c"SSH_CONNECTION\00"
@.str.3 = [24 x i8] c" Login from console %s\0A\00"
@.str.5 = [8 x i8] c"not set\00"
@.str.6 = [23 x i8] c"Connection from: %s %s\00"
@.str.7 = [42 x i8] c"Try to login from unallowed address %s %s\00"
@SIGTERM = global i32 0
@SIGBUS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = call i32 @time(i32* %3)
%6 = call i32* @fopen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%7 = call i8* @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = call i8* @ctime(i32* %3)
%11 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %6, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %10)
%12 = call i32 @fflush(i32* %6)
%13 = call i32 @fclose(i32* %6)
br label %52
14: ; preds = %2
%15 = call dereferenceable_or_null(16384) i8* @malloc(i32 16384)
%16 = call i8* @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%17 = icmp eq i8* %16, null
%18 = select i1 %17, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* %16
%19 = call i8* @strcpy(i8* dereferenceable(1) %15, i8* dereferenceable(1) %18)
%20 = call i8* @ctime(i32* %3)
%21 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %6, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i8* %15, i8* %20)
%22 = call i32 @fflush(i32* %6)
%23 = icmp sgt i32 %0, 1
br i1 %23, label %24, label %35
24: ; preds = %14
%25 = zext i32 %0 to i64
br label %28
26: ; preds = %28
%27 = icmp eq i64 %34, %25
br i1 %27, label %35, label %28
28: ; preds = %24, %26
%29 = phi i64 [ 1, %24 ], [ %34, %26 ]
%30 = getelementptr inbounds i8*, i8** %1, i64 %29
%31 = load i8*, i8** %30
%32 = call i64 @match(i8* %15, i8* %31)
%33 = icmp eq i64 %32, 0
%34 = add nuw nsw i64 %29, 1
br i1 %33, label %52, label %26
35: ; preds = %26, %14
%36 = call i8* @ctime(i32* %3)
%37 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %6, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0), i8* %15, i8* %36)
%38 = call i32 @fflush(i32* %6)
%39 = call i32 @sleep(i32 0)
%40 = call i32 @free(i8* %15)
%41 = call i32 @fclose(i32* %6)
%42 = call i32 (...) @getppid()
%43 = load i32, i32* @SIGTERM
%44 = call i32 @kill(i32 %42, i32 %43)
%45 = call i32 (...) @getppid()
%46 = load i32, i32* @SIGBUS
%47 = call i32 @kill(i32 %45, i32 %46)
%48 = load i32, i32* @SIGTERM
%49 = call i32 @kill(i32 0, i32 %48)
%50 = load i32, i32* @SIGBUS
%51 = call i32 @kill(i32 0, i32 %50)
br label %52
52: ; preds = %28, %35, %9
%53 = phi i32 [ -1, %9 ], [ 1, %35 ], [ 0, %28 ]
ret i32 %53
}