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

/* Variables and functions */
int /*<<< orphan*/ LC_CTYPE;
int MAXPATHLEN;
int /*<<< orphan*/ _PATH_DEV;
int /*<<< orphan*/ do_write(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ done(int /*<<< orphan*/);
int /*<<< orphan*/ errx(int, char *, ...);
int /*<<< orphan*/ exit(int);
int fileno(int /*<<< orphan*/);
int getopt(int, char **, char *);
int /*<<< orphan*/ getuid();
scalar_t__ isatty(int);
scalar_t__ optind;
int /*<<< orphan*/ search_utmp(char *, char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ setlocale(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strlen(int /*<<< orphan*/);
int /*<<< orphan*/ strncmp(char *, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ term_chk(char *, int *, int /*<<< orphan*/ *, int);
char *ttyname(int);
int /*<<< orphan*/ usage();
int /*<<< orphan*/ utmp_chk(char *, char *);
int main(int argc, char **argv) {
  time_t atime;
  uid_t myuid;
  int msgsok, myttyfd;
  char tty[MAXPATHLEN], *mytty;
  (void)setlocale(LC_CTYPE, "");
  while (getopt(argc, argv, "") != -1)
    usage();
  argc -= optind;
  argv += optind;
  if (isatty(fileno(stdin)))
    myttyfd = fileno(stdin);
  else if (isatty(fileno(stdout)))
    myttyfd = fileno(stdout);
  else if (isatty(fileno(stderr)))
    myttyfd = fileno(stderr);
  else
    errx(1, "can't find your tty");
  if (!(mytty = ttyname(myttyfd)))
    errx(1, "can't find your tty's name");
  if (!strncmp(mytty, _PATH_DEV, strlen(_PATH_DEV)))
    mytty += strlen(_PATH_DEV);
  if (term_chk(mytty, &msgsok, &atime, 1))
    exit(1);
  if (!msgsok)
    errx(1, "you have write permission turned off");
  myuid = getuid();
  switch (argc) {
  case 1:
    search_utmp(argv[0], tty, mytty, myuid);
    do_write(tty, mytty, myuid);
    break;
  case 2:
    if (!strncmp(argv[1], _PATH_DEV, strlen(_PATH_DEV)))
      argv[1] += strlen(_PATH_DEV);
    if (utmp_chk(argv[0], argv[1]))
      errx(1, "%s is not logged in on %s", argv[0], argv[1]);
    if (term_chk(argv[1], &msgsok, &atime, 1))
      exit(1);
    if (myuid && !msgsok)
      errx(1, "%s has messages disabled on %s", argv[0], argv[1]);
    do_write(argv[1], mytty, myuid);
    break;
  default:
    usage();
  }
  done(0);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2db3(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    0x2d9f(%rip),%rax
mov    (%rax),%edi
lea    0xddc(%rip),%rsi
call   10f0 <setlocale@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xdc9(%rip),%rdx
call   1110 <getopt@plt>
cmp    $0xffffffff,%eax
je     127f <main+0x7f>
mov    $0x0,%al
call   1100 <usage@plt>
jmp    1257 <main+0x57>
mov    0x2d42(%rip),%rax
mov    (%rax),%rcx
movslq -0x8(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x8(%rbp)
mov    0x2d2e(%rip),%rax
mov    (%rax),%rax
shl    $0x3,%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    0x2d30(%rip),%rax
mov    (%rax),%edi
call   10d0 <fileno@plt>
mov    %eax,%edi
call   1060 <isatty@plt>
cmp    $0x0,%rax
je     12de <main+0xde>
mov    0x2d11(%rip),%rax
mov    (%rax),%edi
call   10d0 <fileno@plt>
mov    %eax,-0x20(%rbp)
jmp    1365 <main+0x165>
mov    0x2ccb(%rip),%rax
mov    (%rax),%edi
call   10d0 <fileno@plt>
mov    %eax,%edi
call   1060 <isatty@plt>
cmp    $0x0,%rax
je     1313 <main+0x113>
mov    0x2cac(%rip),%rax
mov    (%rax),%edi
call   10d0 <fileno@plt>
mov    %eax,-0x20(%rbp)
jmp    1360 <main+0x160>
mov    0x2c9e(%rip),%rax
mov    (%rax),%edi
call   10d0 <fileno@plt>
mov    %eax,%edi
call   1060 <isatty@plt>
cmp    $0x0,%rax
je     1348 <main+0x148>
mov    0x2c7f(%rip),%rax
mov    (%rax),%edi
call   10d0 <fileno@plt>
mov    %eax,-0x20(%rbp)
jmp    135b <main+0x15b>
mov    $0x1,%edi
lea    0xcac(%rip),%rsi
mov    $0x0,%al
call   10b0 <errx@plt>
jmp    1360 <main+0x160>
jmp    1365 <main+0x165>
mov    -0x20(%rbp),%edi
call   10e0 <ttyname@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    138e <main+0x18e>
mov    $0x1,%edi
lea    0xc8d(%rip),%rsi
mov    $0x0,%al
call   10b0 <errx@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    0x2c3b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    0x2c2f(%rip),%rax
mov    (%rax),%edi
call   1090 <strlen@plt>
mov    -0x50(%rbp),%rdi
mov    -0x44(%rbp),%esi
mov    %eax,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    13e5 <main+0x1e5>
mov    0x2c0a(%rip),%rax
mov    (%rax),%edi
call   1090 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
lea    -0x14(%rbp),%rdx
mov    $0x1,%ecx
call   1080 <term_chk@plt>
cmp    $0x0,%rax
je     140f <main+0x20f>
mov    $0x1,%edi
call   1120 <exit@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    142c <main+0x22c>
mov    $0x1,%edi
lea    0xc0a(%rip),%rsi
mov    $0x0,%al
call   10b0 <errx@plt>
xor    %eax,%eax
call   10a0 <getuid@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x54(%rbp)
sub    $0x1,%eax
je     145b <main+0x25b>
jmp    144a <main+0x24a>
mov    -0x54(%rbp),%eax
sub    $0x2,%eax
je     1487 <main+0x287>
jmp    15a2 <main+0x3a2>
mov    -0x40(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x38(%rbp),%rdx
mov    -0x18(%rbp),%ecx
call   1030 <search_utmp@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1050 <do_write@plt>
jmp    15a9 <main+0x3a9>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x60(%rbp)
mov    0x2b3e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x58(%rbp)
mov    0x2b32(%rip),%rax
mov    (%rax),%edi
call   1090 <strlen@plt>
mov    -0x60(%rbp),%rdi
mov    -0x58(%rbp),%esi
mov    %eax,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    14e6 <main+0x2e6>
mov    0x2b0d(%rip),%rax
mov    (%rax),%edi
call   1090 <strlen@plt>
mov    %eax,%edx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
movslq %edx,%rdx
add    %rdx,%rcx
mov    %rcx,0x8(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   10c0 <utmp_chk@plt>
cmp    $0x0,%eax
je     1525 <main+0x325>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    $0x1,%edi
lea    0xb36(%rip),%rsi
mov    $0x0,%al
call   10b0 <errx@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x1c(%rbp),%rsi
lea    -0x14(%rbp),%rdx
mov    $0x1,%ecx
call   1080 <term_chk@plt>
cmp    $0x0,%rax
je     1553 <main+0x353>
mov    $0x1,%edi
call   1120 <exit@plt>
cmpl   $0x0,-0x18(%rbp)
je     1589 <main+0x389>
cmpl   $0x0,-0x1c(%rbp)
jne    1589 <main+0x389>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    $0x1,%edi
lea    0xaec(%rip),%rsi
mov    $0x0,%al
call   10b0 <errx@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1050 <do_write@plt>
jmp    15a9 <main+0x3a9>
mov    $0x0,%al
call   1100 <usage@plt>
xor    %edi,%edi
call   1070 <done@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r12
mov    %edi,%r13d
mov    %rsp,-0x40(%rbp)
mov    0x2dae(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r14
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
lea    0xde9(%rip),%rbx
mov    %rbx,%rsi
call   10f0 <setlocale@plt>
mov    %r13d,%edi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1110 <getopt@plt>
cmp    $0xffffffff,%eax
je     128a <main+0x8a>
lea    0xdc7(%rip),%rbx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1100 <usage@plt>
mov    %r13d,%edi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1110 <getopt@plt>
cmp    $0xffffffff,%eax
jne    1270 <main+0x70>
mov    0x2d37(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x48(%rbp)
mov    0x2d41(%rip),%rbx
mov    (%rbx),%edi
call   10d0 <fileno@plt>
mov    %eax,%edi
call   1060 <isatty@plt>
test   %rax,%rax
jne    12ea <main+0xea>
mov    0x2cf7(%rip),%rbx
mov    (%rbx),%edi
call   10d0 <fileno@plt>
mov    %eax,%edi
call   1060 <isatty@plt>
test   %rax,%rax
jne    12ea <main+0xea>
mov    0x2ce5(%rip),%rbx
mov    (%rbx),%edi
call   10d0 <fileno@plt>
mov    %eax,%edi
call   1060 <isatty@plt>
test   %rax,%rax
je     14b7 <main+0x2b7>
mov    (%rbx),%edi
call   10d0 <fileno@plt>
mov    %eax,%edi
call   10e0 <ttyname@plt>
mov    %rax,%r15
test   %rax,%rax
jne    1313 <main+0x113>
lea    0xd0d(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   10b0 <errx@plt>
mov    0x2cbe(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   1090 <strlen@plt>
mov    %r15,%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1040 <strncmp@plt>
test   %eax,%eax
jne    1346 <main+0x146>
mov    0x2c9e(%rip),%rax
mov    (%rax),%edi
call   1090 <strlen@plt>
cltq
add    %rax,%r15
lea    -0x2c(%rbp),%rsi
lea    -0x34(%rbp),%rdx
mov    %r15,%rdi
mov    $0x1,%ecx
call   1080 <term_chk@plt>
test   %rax,%rax
mov    -0x48(%rbp),%rbx
jne    14ad <main+0x2ad>
sub    %ebx,%r13d
cmpl   $0x0,-0x2c(%rbp)
jne    1384 <main+0x184>
lea    0xcb7(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   10b0 <errx@plt>
xor    %eax,%eax
call   10a0 <getuid@plt>
cmp    $0x2,%r13d
je     13b7 <main+0x1b7>
cmp    $0x1,%r13d
jne    13e9 <main+0x1e9>
mov    (%r12,%rbx,8),%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %eax,%ecx
mov    %eax,%ebx
call   1030 <search_utmp@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
jmp    148c <main+0x28c>
mov    %eax,-0x30(%rbp)
mov    0x8(%r12,%rbx,8),%r14
mov    %rbx,%r13
mov    0x2c0f(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   1090 <strlen@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1040 <strncmp@plt>
test   %eax,%eax
je     13f5 <main+0x1f5>
mov    0x8(%r12,%r13,8),%rsi
jmp    1410 <main+0x210>
xor    %eax,%eax
call   1100 <usage@plt>
jmp    1491 <main+0x291>
mov    0x2bdc(%rip),%rax
mov    (%rax),%edi
call   1090 <strlen@plt>
movslq %eax,%rsi
add    0x8(%r12,%r13,8),%rsi
mov    %rsi,0x8(%r12,%r13,8)
mov    %r13,%rbx
mov    (%r12,%r13,8),%rdi
call   10c0 <utmp_chk@plt>
test   %eax,%eax
je     143c <main+0x23c>
mov    (%r12,%rbx,8),%rdx
mov    0x8(%r12,%rbx,8),%rcx
lea    0xc24(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   10b0 <errx@plt>
mov    0x8(%r12,%rbx,8),%rdi
lea    -0x2c(%rbp),%rsi
lea    -0x34(%rbp),%rdx
mov    $0x1,%ecx
call   1080 <term_chk@plt>
test   %rax,%rax
jne    14ad <main+0x2ad>
mov    -0x30(%rbp),%edx
test   %edx,%edx
je     1484 <main+0x284>
cmpl   $0x0,-0x2c(%rbp)
jne    1484 <main+0x284>
mov    (%r12,%rbx,8),%rdx
mov    0x8(%r12,%rbx,8),%rcx
lea    0xbf9(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   10b0 <errx@plt>
mov    -0x30(%rbp),%edx
mov    0x8(%r12,%rbx,8),%rdi
mov    %r15,%rsi
call   1050 <do_write@plt>
xor    %edi,%edi
call   1070 <done@plt>
mov    -0x40(%rbp),%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%edi
call   1120 <exit@plt>
lea    0xb42(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   10b0 <errx@plt>

LLVM IR (-O0):
@MAXPATHLEN = global i32 0
@LC_CTYPE = global i32 0
@.str = [1 x i8] zeroinitializer
@optind = global i64 0
@stdin = global i32 0
@stdout = global i32 0
@stderr = global i32 0
@.str.1 = [20 x i8] c"can't find your tty\00"
@.str.2 = [27 x i8] c"can't find your tty's name\00"
@_PATH_DEV = global i32 0
@.str.3 = [37 x i8] c"you have write permission turned off\00"
@.str.4 = [26 x i8] c"%s is not logged in on %s\00"
@.str.5 = [31 x i8] c"%s has messages disabled on %s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* @MAXPATHLEN
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %10
%16 = alloca i8, i64 %14
store i64 %14, i64* %11
%17 = load i32, i32* @LC_CTYPE
%18 = call i32 @setlocale(i32 %17, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %24, %2
%20 = load i32, i32* %4
%21 = load i8**, i8*** %5
%22 = call i32 @getopt(i32 %20, i8** %21, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%23 = icmp ne i32 %22, -1
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = call i32 (...) @usage()
br label %19
26: ; preds = %19
%27 = load i64, i64* @optind
%28 = load i32, i32* %4
%29 = sext i32 %28 to i64
%30 = sub nsw i64 %29, %27
%31 = trunc i64 %30 to i32
store i32 %31, i32* %4
%32 = load i64, i64* @optind
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 %32
store i8** %34, i8*** %5
%35 = load i32, i32* @stdin
%36 = call i32 @fileno(i32 %35)
%37 = call i64 @isatty(i32 %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %26
%40 = load i32, i32* @stdin
%41 = call i32 @fileno(i32 %40)
store i32 %41, i32* %9
br label %62
42: ; preds = %26
%43 = load i32, i32* @stdout
%44 = call i32 @fileno(i32 %43)
%45 = call i64 @isatty(i32 %44)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %42
%48 = load i32, i32* @stdout
%49 = call i32 @fileno(i32 %48)
store i32 %49, i32* %9
br label %61
50: ; preds = %42
%51 = load i32, i32* @stderr
%52 = call i32 @fileno(i32 %51)
%53 = call i64 @isatty(i32 %52)
%54 = icmp ne i64 %53, 0
br i1 %54, label %55, label %58
55: ; preds = %50
%56 = load i32, i32* @stderr
%57 = call i32 @fileno(i32 %56)
store i32 %57, i32* %9
br label %60
58: ; preds = %50
%59 = call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %60
60: ; preds = %58, %55
br label %61
61: ; preds = %60, %47
br label %62
62: ; preds = %61, %39
%63 = load i32, i32* %9
%64 = call i8* @ttyname(i32 %63)
store i8* %64, i8** %12
%65 = icmp ne i8* %64, null
br i1 %65, label %68, label %66
66: ; preds = %62
%67 = call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %68
68: ; preds = %66, %62
%69 = load i8*, i8** %12
%70 = load i32, i32* @_PATH_DEV
%71 = load i32, i32* @_PATH_DEV
%72 = call i32 @strlen(i32 %71)
%73 = call i32 @strncmp(i8* %69, i32 %70, i32 %72)
%74 = icmp ne i32 %73, 0
br i1 %74, label %81, label %75
75: ; preds = %68
%76 = load i32, i32* @_PATH_DEV
%77 = call i32 @strlen(i32 %76)
%78 = load i8*, i8** %12
%79 = sext i32 %77 to i64
%80 = getelementptr inbounds i8, i8* %78, i64 %79
store i8* %80, i8** %12
br label %81
81: ; preds = %75, %68
%82 = load i8*, i8** %12
%83 = call i64 @term_chk(i8* %82, i32* %8, i32* %6, i32 1)
%84 = icmp ne i64 %83, 0
br i1 %84, label %85, label %87
85: ; preds = %81
%86 = call i32 @exit(i32 1)
unreachable
87: ; preds = %81
%88 = load i32, i32* %8
%89 = icmp ne i32 %88, 0
br i1 %89, label %92, label %90
90: ; preds = %87
%91 = call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0))
br label %92
92: ; preds = %90, %87
%93 = call i32 (...) @getuid()
store i32 %93, i32* %7
%94 = load i32, i32* %4
switch i32 %94, label %168 [
i32 1, label %95
i32 2, label %105
]
95: ; preds = %92
%96 = load i8**, i8*** %5
%97 = getelementptr inbounds i8*, i8** %96, i64 0
%98 = load i8*, i8** %97
%99 = load i8*, i8** %12
%100 = load i32, i32* %7
%101 = call i32 @search_utmp(i8* %98, i8* %16, i8* %99, i32 %100)
%102 = load i8*, i8** %12
%103 = load i32, i32* %7
%104 = call i32 @do_write(i8* %16, i8* %102, i32 %103)
br label %170
105: ; preds = %92
%106 = load i8**, i8*** %5
%107 = getelementptr inbounds i8*, i8** %106, i64 1
%108 = load i8*, i8** %107
%109 = load i32, i32* @_PATH_DEV
%110 = load i32, i32* @_PATH_DEV
%111 = call i32 @strlen(i32 %110)
%112 = call i32 @strncmp(i8* %108, i32 %109, i32 %111)
%113 = icmp ne i32 %112, 0
br i1 %113, label %122, label %114
114: ; preds = %105
%115 = load i32, i32* @_PATH_DEV
%116 = call i32 @strlen(i32 %115)
%117 = load i8**, i8*** %5
%118 = getelementptr inbounds i8*, i8** %117, i64 1
%119 = load i8*, i8** %118
%120 = sext i32 %116 to i64
%121 = getelementptr inbounds i8, i8* %119, i64 %120
store i8* %121, i8** %118
br label %122
122: ; preds = %114, %105
%123 = load i8**, i8*** %5
%124 = getelementptr inbounds i8*, i8** %123, i64 0
%125 = load i8*, i8** %124
%126 = load i8**, i8*** %5
%127 = getelementptr inbounds i8*, i8** %126, i64 1
%128 = load i8*, i8** %127
%129 = call i32 @utmp_chk(i8* %125, i8* %128)
%130 = icmp ne i32 %129, 0
br i1 %130, label %131, label %139
131: ; preds = %122
%132 = load i8**, i8*** %5
%133 = getelementptr inbounds i8*, i8** %132, i64 0
%134 = load i8*, i8** %133
%135 = load i8**, i8*** %5
%136 = getelementptr inbounds i8*, i8** %135, i64 1
%137 = load i8*, i8** %136
%138 = call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %134, i8* %137)
br label %139
139: ; preds = %131, %122
%140 = load i8**, i8*** %5
%141 = getelementptr inbounds i8*, i8** %140, i64 1
%142 = load i8*, i8** %141
%143 = call i64 @term_chk(i8* %142, i32* %8, i32* %6, i32 1)
%144 = icmp ne i64 %143, 0
br i1 %144, label %145, label %147
145: ; preds = %139
%146 = call i32 @exit(i32 1)
unreachable
147: ; preds = %139
%148 = load i32, i32* %7
%149 = icmp ne i32 %148, 0
br i1 %149, label %150, label %161
150: ; preds = %147
%151 = load i32, i32* %8
%152 = icmp ne i32 %151, 0
br i1 %152, label %161, label %153
153: ; preds = %150
%154 = load i8**, i8*** %5
%155 = getelementptr inbounds i8*, i8** %154, i64 0
%156 = load i8*, i8** %155
%157 = load i8**, i8*** %5
%158 = getelementptr inbounds i8*, i8** %157, i64 1
%159 = load i8*, i8** %158
%160 = call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), i8* %156, i8* %159)
br label %161
161: ; preds = %153, %150, %147
%162 = load i8**, i8*** %5
%163 = getelementptr inbounds i8*, i8** %162, i64 1
%164 = load i8*, i8** %163
%165 = load i8*, i8** %12
%166 = load i32, i32* %7
%167 = call i32 @do_write(i8* %164, i8* %165, i32 %166)
br label %170
168: ; preds = %92
%169 = call i32 (...) @usage()
br label %170
170: ; preds = %168, %161, %95
%171 = call i32 @done(i32 0)
store i32 0, i32* %3
%172 = load i8*, i8** %10
%173 = load i32, i32* %3
ret i32 %173
}

LLVM IR (-O2):
@MAXPATHLEN = global i32 0
@LC_CTYPE = global i32 0
@.str = [1 x i8] zeroinitializer
@optind = global i64 0
@stdin = global i32 0
@stdout = global i32 0
@stderr = global i32 0
@.str.1 = [20 x i8] c"can't find your tty\00"
@.str.2 = [27 x i8] c"can't find your tty's name\00"
@_PATH_DEV = global i32 0
@.str.3 = [37 x i8] c"you have write permission turned off\00"
@.str.4 = [26 x i8] c"%s is not logged in on %s\00"
@.str.5 = [31 x i8] c"%s has messages disabled on %s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = load i32, i32* @MAXPATHLEN
%8 = zext i32 %7 to i64
%9 = tail call i8* @llvm.stacksave()
%10 = alloca i8, i64 %8
%11 = load i32, i32* @LC_CTYPE
%12 = tail call i32 @setlocale(i32 %11, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i32 %13, -1
br i1 %14, label %19, label %15
15: ; preds = %2, %15
%16 = tail call i32 (...) @usage()
%17 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %15
19: ; preds = %15, %2
%20 = load i64, i64* @optind
%21 = trunc i64 %20 to i32
%22 = sub i32 %0, %21
%23 = getelementptr inbounds i8*, i8** %1, i64 %20
%24 = load i32, i32* @stdin
%25 = tail call i32 @fileno(i32 %24)
%26 = tail call i64 @isatty(i32 %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %40
28: ; preds = %19
%29 = load i32, i32* @stdout
%30 = tail call i32 @fileno(i32 %29)
%31 = tail call i64 @isatty(i32 %30)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %40
33: ; preds = %28
%34 = load i32, i32* @stderr
%35 = tail call i32 @fileno(i32 %34)
%36 = tail call i64 @isatty(i32 %35)
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %33
%39 = tail call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
unreachable
40: ; preds = %33, %28, %19
%41 = phi i32* [ @stdin, %19 ], [ @stdout, %28 ], [ @stderr, %33 ]
%42 = load i32, i32* %41
%43 = tail call i32 @fileno(i32 %42)
%44 = tail call i8* @ttyname(i32 %43)
%45 = icmp eq i8* %44, null
br i1 %45, label %46, label %48
46: ; preds = %40
%47 = tail call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %48
48: ; preds = %46, %40
%49 = load i32, i32* @_PATH_DEV
%50 = tail call i32 @strlen(i32 %49)
%51 = tail call i32 @strncmp(i8* %44, i32 %49, i32 %50)
%52 = icmp eq i32 %51, 0
br i1 %52, label %53, label %58
53: ; preds = %48
%54 = load i32, i32* @_PATH_DEV
%55 = tail call i32 @strlen(i32 %54)
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %44, i64 %56
br label %58
58: ; preds = %53, %48
%59 = phi i8* [ %44, %48 ], [ %57, %53 ]
%60 = call i64 @term_chk(i8* %59, i32* %4, i32* %3, i32 1)
%61 = icmp eq i64 %60, 0
br i1 %61, label %64, label %62
62: ; preds = %58
%63 = call i32 @exit(i32 1)
unreachable
64: ; preds = %58
%65 = load i32, i32* %4
%66 = icmp eq i32 %65, 0
br i1 %66, label %67, label %69
67: ; preds = %64
%68 = call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0))
br label %69
69: ; preds = %67, %64
%70 = call i32 (...) @getuid()
switch i32 %22, label %117 [
i32 1, label %71
i32 2, label %75
]
71: ; preds = %69
%72 = load i8*, i8** %23
%73 = call i32 @search_utmp(i8* %72, i8* %10, i8* %59, i32 %70)
%74 = call i32 @do_write(i8* %10, i8* %59, i32 %70)
br label %119
75: ; preds = %69
%76 = getelementptr inbounds i8*, i8** %23, i64 1
%77 = load i8*, i8** %76
%78 = load i32, i32* @_PATH_DEV
%79 = call i32 @strlen(i32 %78)
%80 = call i32 @strncmp(i8* %77, i32 %78, i32 %79)
%81 = icmp eq i32 %80, 0
br i1 %81, label %84, label %82
82: ; preds = %75
%83 = load i8*, i8** %76
br label %90
84: ; preds = %75
%85 = load i32, i32* @_PATH_DEV
%86 = call i32 @strlen(i32 %85)
%87 = load i8*, i8** %76
%88 = sext i32 %86 to i64
%89 = getelementptr inbounds i8, i8* %87, i64 %88
store i8* %89, i8** %76
br label %90
90: ; preds = %82, %84
%91 = phi i8* [ %83, %82 ], [ %89, %84 ]
%92 = load i8*, i8** %23
%93 = call i32 @utmp_chk(i8* %92, i8* %91)
%94 = icmp eq i32 %93, 0
br i1 %94, label %99, label %95
95: ; preds = %90
%96 = load i8*, i8** %23
%97 = load i8*, i8** %76
%98 = call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %96, i8* %97)
br label %99
99: ; preds = %95, %90
%100 = load i8*, i8** %76
%101 = call i64 @term_chk(i8* %100, i32* %4, i32* %3, i32 1)
%102 = icmp eq i64 %101, 0
br i1 %102, label %105, label %103
103: ; preds = %99
%104 = call i32 @exit(i32 1)
unreachable
105: ; preds = %99
%106 = icmp eq i32 %70, 0
%107 = load i32, i32* %4
%108 = icmp ne i32 %107, 0
%109 = select i1 %106, i1 true, i1 %108
br i1 %109, label %114, label %110
110: ; preds = %105
%111 = load i8*, i8** %23
%112 = load i8*, i8** %76
%113 = call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), i8* %111, i8* %112)
br label %114
114: ; preds = %110, %105
%115 = load i8*, i8** %76
%116 = call i32 @do_write(i8* %115, i8* %59, i32 %70)
br label %119
117: ; preds = %69
%118 = call i32 (...) @usage()
br label %119
119: ; preds = %117, %114, %71
%120 = call i32 @done(i32 0)
ret i32 0
}