#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_ALL;
int MAXPATHLEN;
int /*<<< orphan*/ bindtextdomain(char *, char *);
int /*<<< orphan*/ do_write(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ done(int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int fileno(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
char *gettext(char *);
int /*<<< orphan*/ getuid();
scalar_t__ isatty(int);
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*/ strncmp(char *, char *, int);
scalar_t__ term_chk(char *, int *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ textdomain(char *);
char *ttyname(int);
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;
  setlocale(LC_ALL, "");
  bindtextdomain("util-linux", "/usr/share/locale");
  textdomain("util-linux");
  if (isatty(fileno(stdin)))
    myttyfd = fileno(stdin);
  else if (isatty(fileno(stdout)))
    myttyfd = fileno(stdout);
  else if (isatty(fileno(stderr)))
    myttyfd = fileno(stderr);
  else {
    myttyfd = -1;
  }
  if (myttyfd != -1) {
    if (!(mytty = ttyname(myttyfd))) {
      (void)fprintf(stderr, gettext("write: can't find your tty's name\n"));
      exit(1);
    }
    if (!strncmp(mytty, "/dev/", 5))
      mytty += 5;
    if (term_chk(mytty, &msgsok, &atime, 1))
      exit(1);
    if (!msgsok) {
      (void)fprintf(stderr,
                    gettext("write: you have write permission turned off.\n"));
      exit(1);
    }
  } else {
    mytty = "<no tty>";
  }
  myuid = getuid();
  switch (argc) {
  case 2:
    search_utmp(argv[1], tty, mytty, myuid);
    do_write(tty, mytty, myuid);
    break;
  case 3:
    if (!strncmp(argv[2], "/dev/", 5))
      argv[2] += 5;
    if (utmp_chk(argv[1], argv[2])) {
      (void)fprintf(stderr, gettext("write: %s is not logged in on %s.\n"),
                    argv[1], argv[2]);
      exit(1);
    }
    if (term_chk(argv[2], &msgsok, &atime, 1))
      exit(1);
    if (myuid && !msgsok) {
      (void)fprintf(stderr, gettext("write: %s has messages disabled on %s\n"),
                    argv[1], argv[2]);
      exit(1);
    }
    do_write(argv[2], mytty, myuid);
    break;
  default:
    (void)fprintf(stderr, gettext("usage: write user [tty]\n"));
    exit(1);
  }
  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    0x2dc3(%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    0x2d77(%rip),%rax
mov    (%rax),%edi
lea    0xe21(%rip),%rsi
call   1110 <setlocale@plt>
lea    0xda2(%rip),%rdi
lea    0xda6(%rip),%rsi
call   1090 <bindtextdomain@plt>
lea    0xd8f(%rip),%rdi
call   1080 <textdomain@plt>
mov    0x2d6b(%rip),%rax
mov    (%rax),%edi
call   10f0 <fileno@plt>
mov    %eax,%edi
call   1060 <isatty@plt>
cmp    $0x0,%rax
je     12ab <main+0xab>
mov    0x2d4c(%rip),%rax
mov    (%rax),%edi
call   10f0 <fileno@plt>
mov    %eax,-0x20(%rbp)
jmp    1326 <main+0x126>
mov    0x2d16(%rip),%rax
mov    (%rax),%edi
call   10f0 <fileno@plt>
mov    %eax,%edi
call   1060 <isatty@plt>
cmp    $0x0,%rax
je     12e0 <main+0xe0>
mov    0x2cf7(%rip),%rax
mov    (%rax),%edi
call   10f0 <fileno@plt>
mov    %eax,-0x20(%rbp)
jmp    1321 <main+0x121>
mov    0x2ce9(%rip),%rax
mov    (%rax),%edi
call   10f0 <fileno@plt>
mov    %eax,%edi
call   1060 <isatty@plt>
cmp    $0x0,%rax
je     1315 <main+0x115>
mov    0x2cca(%rip),%rax
mov    (%rax),%edi
call   10f0 <fileno@plt>
mov    %eax,-0x20(%rbp)
jmp    131c <main+0x11c>
movl   $0xffffffff,-0x20(%rbp)
jmp    1321 <main+0x121>
jmp    1326 <main+0x126>
cmpl   $0xffffffff,-0x20(%rbp)
je     1407 <main+0x207>
mov    -0x20(%rbp),%edi
call   1100 <ttyname@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    1375 <main+0x175>
mov    0x2c83(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
lea    0xcc4(%rip),%rdi
call   10c0 <gettext@plt>
mov    -0x44(%rbp),%edi
mov    %rax,%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    -0x38(%rbp),%rdi
lea    0xcc0(%rip),%rsi
mov    $0x5,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    139f <main+0x19f>
mov    -0x38(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
lea    -0x14(%rbp),%rdx
mov    $0x1,%ecx
call   10a0 <term_chk@plt>
cmp    $0x0,%rax
je     13c9 <main+0x1c9>
mov    $0x1,%edi
call   1120 <exit@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    1402 <main+0x202>
mov    0x2bf6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
lea    0xc60(%rip),%rdi
call   10c0 <gettext@plt>
mov    -0x48(%rbp),%edi
mov    %rax,%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
jmp    1412 <main+0x212>
lea    0xc66(%rip),%rax
mov    %rax,-0x38(%rbp)
xor    %eax,%eax
call   10b0 <getuid@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x4c(%rbp)
sub    $0x2,%eax
je     1441 <main+0x241>
jmp    1430 <main+0x230>
mov    -0x4c(%rbp),%eax
sub    $0x3,%eax
je     146e <main+0x26e>
jmp    1597 <main+0x397>
mov    -0x40(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    0x8(%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    15c6 <main+0x3c6>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xbc3(%rip),%rsi
mov    $0x5,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    14a0 <main+0x2a0>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rcx
add    $0x5,%rcx
mov    %rcx,0x10(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   10d0 <utmp_chk@plt>
cmp    $0x0,%eax
je     14fd <main+0x2fd>
mov    0x2b0b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x50(%rbp)
lea    0xbac(%rip),%rdi
call   10c0 <gettext@plt>
mov    -0x50(%rbp),%edi
mov    %rax,%rsi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rcx
mov    $0x0,%al
call   10e0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x1c(%rbp),%rsi
lea    -0x14(%rbp),%rdx
mov    $0x1,%ecx
call   10a0 <term_chk@plt>
cmp    $0x0,%rax
je     152b <main+0x32b>
mov    $0x1,%edi
call   1120 <exit@plt>
cmpl   $0x0,-0x18(%rbp)
je     157e <main+0x37e>
cmpl   $0x0,-0x1c(%rbp)
jne    157e <main+0x37e>
mov    0x2a8a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
lea    0xb4e(%rip),%rdi
call   10c0 <gettext@plt>
mov    -0x54(%rbp),%edi
mov    %rax,%rsi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rcx
mov    $0x0,%al
call   10e0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1050 <do_write@plt>
jmp    15c6 <main+0x3c6>
mov    0x2a32(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x58(%rbp)
lea    0xb1d(%rip),%rdi
call   10c0 <gettext@plt>
mov    -0x58(%rbp),%edi
mov    %rax,%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@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    $0x18,%rsp
mov    %rsi,%r14
mov    %edi,-0x30(%rbp)
mov    %rsp,%r13
mov    0x2dbf(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r12
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    0x2d85(%rip),%rax
mov    (%rax),%edi
lea    0xe2f(%rip),%rsi
call   1110 <setlocale@plt>
lea    0xdb0(%rip),%rbx
lea    0xdb4(%rip),%rsi
mov    %rbx,%rdi
call   1090 <bindtextdomain@plt>
mov    %rbx,%rdi
call   1080 <textdomain@plt>
mov    0x2d7a(%rip),%rbx
mov    (%rbx),%edi
call   10f0 <fileno@plt>
mov    %eax,%edi
call   1060 <isatty@plt>
test   %rax,%rax
jne    12b5 <main+0xb5>
mov    0x2d40(%rip),%rbx
mov    (%rbx),%edi
call   10f0 <fileno@plt>
mov    %eax,%edi
call   1060 <isatty@plt>
test   %rax,%rax
jne    12b5 <main+0xb5>
mov    0x2d2e(%rip),%rbx
mov    (%rbx),%edi
call   10f0 <fileno@plt>
mov    %eax,%edi
call   1060 <isatty@plt>
test   %rax,%rax
je     1332 <main+0x132>
mov    (%rbx),%edi
call   10f0 <fileno@plt>
cmp    $0xffffffff,%eax
je     1332 <main+0x132>
mov    %eax,%edi
call   1100 <ttyname@plt>
test   %rax,%rax
je     1402 <main+0x202>
mov    %rax,%rbx
lea    0xd65(%rip),%rsi
mov    %rax,%rdi
mov    $0x5,%edx
call   1040 <strncmp@plt>
xor    %ecx,%ecx
test   %eax,%eax
sete   %cl
lea    (%rcx,%rcx,4),%r15
add    %rbx,%r15
lea    -0x2c(%rbp),%rsi
lea    -0x34(%rbp),%rdx
mov    %r15,%rdi
mov    $0x1,%ecx
call   10a0 <term_chk@plt>
test   %rax,%rax
jne    13f8 <main+0x1f8>
mov    %r13,%rbx
cmpl   $0x0,-0x2c(%rbp)
jne    133c <main+0x13c>
mov    0x2cac(%rip),%rax
mov    (%rax),%ebx
lea    0xd19(%rip),%rdi
jmp    1424 <main+0x224>
mov    %r13,%rbx
lea    0xd38(%rip),%r15
xor    %eax,%eax
call   10b0 <getuid@plt>
mov    %eax,%r13d
mov    -0x30(%rbp),%eax
cmp    $0x3,%eax
je     136e <main+0x16e>
cmp    $0x2,%eax
jne    1414 <main+0x214>
mov    0x8(%r14),%rdi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %r13d,%ecx
call   1030 <search_utmp@plt>
mov    %r12,%rdi
jmp    13d2 <main+0x1d2>
mov    0x10(%r14),%rdi
lea    0xcc7(%rip),%rsi
mov    $0x5,%edx
call   1040 <strncmp@plt>
mov    0x10(%r14),%rsi
test   %eax,%eax
jne    1393 <main+0x193>
add    $0x5,%rsi
mov    %rsi,0x10(%r14)
mov    0x8(%r14),%rdi
call   10d0 <utmp_chk@plt>
test   %eax,%eax
jne    143f <main+0x23f>
mov    0x10(%r14),%rdi
lea    -0x2c(%rbp),%rsi
lea    -0x34(%rbp),%rdx
mov    $0x1,%ecx
call   10a0 <term_chk@plt>
test   %rax,%rax
jne    13f8 <main+0x1f8>
test   %r13d,%r13d
je     13ce <main+0x1ce>
cmpl   $0x0,-0x2c(%rbp)
je     1451 <main+0x251>
mov    0x10(%r14),%rdi
mov    %r15,%rsi
mov    %r13d,%edx
call   1050 <do_write@plt>
xor    %edi,%edi
call   1070 <done@plt>
mov    %rbx,%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>
mov    0x2bc7(%rip),%rax
mov    (%rax),%ebx
lea    0xc0b(%rip),%rdi
jmp    1424 <main+0x224>
mov    0x2bb5(%rip),%rax
mov    (%rax),%ebx
lea    0xca3(%rip),%rdi
call   10c0 <gettext@plt>
mov    %ebx,%edi
mov    %rax,%rsi
xor    %eax,%eax
call   10e0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    0x2b8a(%rip),%rax
mov    (%rax),%ebx
lea    0xc2e(%rip),%rdi
jmp    1461 <main+0x261>
mov    0x2b78(%rip),%rax
mov    (%rax),%ebx
lea    0xc3f(%rip),%rdi
call   10c0 <gettext@plt>
mov    0x8(%r14),%rdx
mov    0x10(%r14),%rcx
mov    %ebx,%edi
mov    %rax,%rsi
xor    %eax,%eax
call   10e0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>

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

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