#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 */
struct utmp {
  scalar_t__ ut_type;
  char *ut_line;
  int /*<<< orphan*/ ut_user;
};
struct stat {
  scalar_t__ st_uid;
};
struct passwd {
  scalar_t__ pw_uid;
  char *pw_name;
};

/* Variables and functions */
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ STDIN_FILENO;
scalar_t__ USER_PROCESS;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
struct passwd *getpwnam(char *);
struct utmp *getutent();
int open(char *, int /*<<< orphan*/);
int read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ setutent();
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, int /*<<< orphan*/);
int strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
int /*<<< orphan*/ usage(char **);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  char ttyname[12];
  struct passwd *pwdent;
  int ofd = -1;
  char buf[255];
  int n;
  if ((argc > 3) || (argc < 2)) {
    usage(argv);
  }
  if ((pwdent = getpwnam(argv[1])) == NULL) {
    fprintf(stderr, "%s: No such user %s\n", argv[0], argv[1]);
    exit(1);
  }
  if (argc == 3) {
    struct stat sbuf;
    strncpy(ttyname, "/dev/", 6);
    strncat(ttyname, argv[2], 6);
    ttyname[11] = '\0';
    if (stat(ttyname, &sbuf) != 0) {
      fprintf(stderr, "%s: No such tty %s\n", argv[0], ttyname);
      exit(1);
    }
    if (pwdent->pw_uid != sbuf.st_uid) {
      fprintf(stderr, "%s: User %s is not logged onto %s\n", argv[0], argv[1],
              argv[2]);
      exit(1);
    }
    if ((ofd = open(ttyname, O_WRONLY)) < 0) {
      fprintf(stderr, "%s: %s has messages disabled on %s\n", argv[0], argv[1],
              argv[2]);
      exit(1);
    }
  } else {
    struct utmp *utmp;
    setutent();
    while ((utmp = getutent()) != NULL) {
      if ((strcmp(pwdent->pw_name, utmp->ut_user) == 0) &&
          (utmp->ut_type == USER_PROCESS)) {
        strncpy(ttyname, "/dev/", 6);
        strncat(ttyname, utmp->ut_line, 6);
        ttyname[11] = '\0';
        if ((ofd = open(ttyname, O_WRONLY)) >= 0) {
          break;
        }
      }
    }
    if (ofd < 0) {
      fprintf(stderr, "%s: User %s not logged in, or has messages disabled\n",
              argv[0], argv[1]);
      exit(1);
    }
  }
  if ((pwdent = getpwnam(argv[1])) == NULL) {
    fprintf(stderr, "%s: Who are you?\n", argv[0]);
    exit(1);
  }
  write(ofd, "Message from ", 13);
  write(ofd, pwdent->pw_name, strlen(pwdent->pw_name));
  write(ofd, "\n", 1);
  while ((n = read(STDIN_FILENO, buf, 254)) > 0) {
    buf[254] = '\0';
    write(ofd, buf, n);
  }
  write(ofd, "EOF\n", 4);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x2c(%rbp)
cmpl   $0x3,-0x8(%rbp)
jg     1214 <main+0x34>
cmpl   $0x2,-0x8(%rbp)
jge    121d <main+0x3d>
mov    -0x10(%rbp),%rdi
call   10d0 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <getpwnam@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1268 <main+0x88>
mov    0x2d99(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0xda9(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
cmpl   $0x3,-0x8(%rbp)
jne    138e <main+0x1ae>
lea    -0x1c(%rbp),%rdi
lea    0xd98(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncpy@plt>
lea    -0x1c(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
mov    $0x6,%edx
call   1060 <strncat@plt>
movb   $0x0,-0x11(%rbp)
lea    -0x1c(%rbp),%rdi
lea    -0x140(%rbp),%rsi
call   10b0 <stat@plt>
cmp    $0x0,%rax
je     12e7 <main+0x107>
mov    0x2d16(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    -0x1c(%rbp),%rcx
lea    0xd45(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
cmp    -0x140(%rbp),%rax
je     1333 <main+0x153>
mov    0x2cd6(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%r8
lea    0xd0d(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
lea    -0x1c(%rbp),%rdi
mov    0x2c82(%rip),%rax
mov    (%rax),%esi
call   10f0 <open@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jge    1389 <main+0x1a9>
mov    0x2c80(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%r8
lea    0xcda(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
jmp    1486 <main+0x2a6>
mov    $0x0,%al
call   10e0 <setutent@plt>
mov    $0x0,%al
call   10c0 <getutent@plt>
mov    %rax,-0x148(%rbp)
cmp    $0x0,%rax
je     1447 <main+0x267>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x148(%rbp),%rax
mov    0x10(%rax),%esi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    1442 <main+0x262>
mov    -0x148(%rbp),%rax
mov    (%rax),%rax
mov    0x2c09(%rip),%rcx
cmp    (%rcx),%rax
jne    1442 <main+0x262>
lea    -0x1c(%rbp),%rdi
lea    0xc22(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncpy@plt>
lea    -0x1c(%rbp),%rdi
mov    -0x148(%rbp),%rax
mov    0x8(%rax),%rsi
mov    $0x6,%edx
call   1060 <strncat@plt>
movb   $0x0,-0x11(%rbp)
lea    -0x1c(%rbp),%rdi
mov    0x2b9b(%rip),%rax
mov    (%rax),%esi
call   10f0 <open@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jl     143d <main+0x25d>
jmp    1447 <main+0x267>
jmp    1442 <main+0x262>
jmp    1395 <main+0x1b5>
cmpl   $0x0,-0x2c(%rbp)
jge    1481 <main+0x2a1>
mov    0x2b80(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0xc06(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
jmp    1486 <main+0x2a6>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <getpwnam@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    14c9 <main+0x2e9>
mov    0x2b30(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xbf3(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    -0x2c(%rbp),%edi
lea    0xbea(%rip),%rsi
mov    $0xd,%edx
call   1040 <write@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x154(%rbp)
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x150(%rbp)
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <strlen@plt>
mov    -0x154(%rbp),%edi
mov    -0x150(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    -0x2c(%rbp),%edi
lea    0xb9b(%rip),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    0x2a9f(%rip),%rax
mov    (%rax),%edi
lea    -0x130(%rbp),%rsi
mov    $0xfe,%edx
call   1070 <read@plt>
mov    %eax,-0x134(%rbp)
cmp    $0x0,%eax
jle    1571 <main+0x391>
movb   $0x0,-0x32(%rbp)
mov    -0x2c(%rbp),%edi
lea    -0x130(%rbp),%rsi
mov    -0x134(%rbp),%edx
call   1040 <write@plt>
jmp    152a <main+0x34a>
mov    -0x2c(%rbp),%edi
lea    0xb50(%rip),%rsi
mov    $0x4,%edx
call   1040 <write@plt>
xor    %edi,%edi
call   1100 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x128,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
lea    -0x4(%rbp),%eax
cmp    $0xfffffffd,%eax
ja     1206 <main+0x26>
mov    %r14,%rdi
call   10d0 <usage@plt>
mov    0x8(%r14),%rdi
call   1090 <getpwnam@plt>
test   %rax,%rax
jne    1230 <main+0x50>
mov    0x2dbd(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
mov    0x8(%r14),%rcx
lea    0xdd5(%rip),%rsi
jmp    13b5 <main+0x1d5>
mov    %rax,%rbx
cmp    $0x3,%ebp
jne    12ca <main+0xea>
lea    0xdd2(%rip),%rsi
lea    0x14(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x6,%edx
call   1030 <strncpy@plt>
mov    0x10(%r14),%rsi
mov    %rbp,%rdi
mov    $0x6,%edx
call   1060 <strncat@plt>
movb   $0x0,0x1f(%rsp)
lea    0x20(%rsp),%rsi
mov    %rbp,%rdi
call   10b0 <stat@plt>
test   %rax,%rax
jne    137a <main+0x19a>
mov    (%rbx),%rax
cmp    0x20(%rsp),%rax
jne    13c6 <main+0x1e6>
mov    0x2d2a(%rip),%rax
mov    (%rax),%esi
lea    0x14(%rsp),%rdi
call   10f0 <open@plt>
test   %eax,%eax
jns    13f2 <main+0x212>
mov    0x2d27(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
mov    0x8(%r14),%rcx
mov    0x10(%r14),%r8
lea    0xd8d(%rip),%rsi
jmp    13e1 <main+0x201>
mov    %r14,0x8(%rsp)
xor    %eax,%eax
call   10e0 <setutent@plt>
xor    %eax,%eax
call   10c0 <getutent@plt>
test   %rax,%rax
je     1399 <main+0x1b9>
mov    %rax,%rbp
mov    $0xffffffff,%r13d
mov    0x2cf2(%rip),%r14
lea    0x14(%rsp),%r12
mov    0x2cbe(%rip),%r15
jmp    131f <main+0x13f>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   10c0 <getutent@plt>
mov    %rax,%rbp
test   %rax,%rax
je     1394 <main+0x1b4>
mov    0x8(%rbx),%rdi
mov    0x10(%rbp),%esi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    1310 <main+0x130>
mov    0x0(%rbp),%rax
cmp    (%r14),%rax
jne    1310 <main+0x130>
mov    %r12,%rdi
lea    0xcd2(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncpy@plt>
mov    0x8(%rbp),%rsi
mov    %r12,%rdi
mov    $0x6,%edx
call   1060 <strncat@plt>
movb   $0x0,0x1f(%rsp)
mov    (%r15),%esi
mov    %r12,%rdi
call   10f0 <open@plt>
mov    %eax,%r13d
test   %eax,%eax
js     1310 <main+0x130>
jmp    13fa <main+0x21a>
mov    0x2c57(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xc8e(%rip),%rsi
lea    0x14(%rsp),%rcx
jmp    13b5 <main+0x1d5>
test   %r13d,%r13d
jns    13fa <main+0x21a>
mov    0x2c38(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rsp),%rax
mov    (%rax),%rdx
mov    0x8(%rax),%rcx
lea    0xcc1(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    0x2c0b(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
mov    0x8(%r14),%rcx
mov    0x10(%r14),%r8
lea    0xc4e(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    %eax,%r13d
mov    %r14,0x8(%rsp)
mov    0x8(%rsp),%rbp
mov    0x8(%rbp),%rdi
call   1090 <getpwnam@plt>
test   %rax,%rax
jne    1432 <main+0x252>
mov    0x2bc4(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
lea    0xc8a(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    %rax,%rbx
lea    0xc81(%rip),%rsi
mov    %r13d,%edi
mov    $0xd,%edx
call   1040 <write@plt>
mov    0x8(%rbx),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
lea    0xc52(%rip),%rsi
mov    %r13d,%edi
mov    $0x1,%edx
call   1040 <write@plt>
mov    0x2b53(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0x20(%rsp),%rsi
mov    $0xfe,%edx
call   1070 <read@plt>
test   %eax,%eax
jle    14c9 <main+0x2e9>
lea    0x20(%rsp),%rbx
nopl   0x0(%rax,%rax,1)
movb   $0x0,0x11e(%rsp)
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    0x0(%rbp),%edi
mov    %rbx,%rsi
mov    $0xfe,%edx
call   1070 <read@plt>
test   %eax,%eax
jg     14a0 <main+0x2c0>
lea    0xbfb(%rip),%rsi
mov    %r13d,%edi
mov    $0x4,%edx
call   1040 <write@plt>
xor    %edi,%edi
call   1100 <exit@plt>

LLVM IR (-O0):
%struct.passwd = type { i64, i8* }
%struct.stat = type { i64 }
%struct.utmp = type { i64, i8*, i32 }
@stderr = global i32 0
@.str = [21 x i8] c"%s: No such user %s\0A\00"
@.str.1 = [6 x i8] c"/dev/\00"
@.str.2 = [20 x i8] c"%s: No such tty %s\0A\00"
@.str.3 = [35 x i8] c"%s: User %s is not logged onto %s\0A\00"
@O_WRONLY = global i32 0
@.str.4 = [36 x i8] c"%s: %s has messages disabled on %s\0A\00"
@USER_PROCESS = global i64 0
@.str.5 = [53 x i8] c"%s: User %s not logged in, or has messages disabled\0A\00"
@.str.6 = [18 x i8] c"%s: Who are you?\0A\00"
@.str.7 = [14 x i8] c"Message from \00"
@.str.8 = [2 x i8] c"\0A\00"
@STDIN_FILENO = global i32 0
@.str.9 = [5 x i8] c"EOF\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [12 x i8]
%7 = alloca %struct.passwd*
%8 = alloca i32
%9 = alloca [255 x i8]
%10 = alloca i32
%11 = alloca %struct.stat
%12 = alloca %struct.utmp*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %8
%13 = load i32, i32* %4
%14 = icmp sgt i32 %13, 3
br i1 %14, label %18, label %15
15: ; preds = %2
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 2
br i1 %17, label %18, label %21
18: ; preds = %15, %2
%19 = load i8**, i8*** %5
%20 = call i32 @usage(i8** %19)
br label %21
21: ; preds = %18, %15
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call %struct.passwd* @getpwnam(i8* %24)
store %struct.passwd* %25, %struct.passwd** %7
%26 = icmp eq %struct.passwd* %25, null
br i1 %26, label %27, label %37
27: ; preds = %21
%28 = load i32, i32* @stderr
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 0
%31 = load i8*, i8** %30
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %31, i8* %34)
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %21
%38 = load i32, i32* %4
%39 = icmp eq i32 %38, 3
br i1 %39, label %40, label %99
40: ; preds = %37
%41 = getelementptr inbounds [12 x i8], [12 x i8]* %6, i64 0, i64 0
%42 = call i32 @strncpy(i8* %41, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 6)
%43 = getelementptr inbounds [12 x i8], [12 x i8]* %6, i64 0, i64 0
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 2
%46 = load i8*, i8** %45
%47 = call i32 @strncat(i8* %43, i8* %46, i32 6)
%48 = getelementptr inbounds [12 x i8], [12 x i8]* %6, i64 0, i64 11
store i8 0, i8* %48
%49 = getelementptr inbounds [12 x i8], [12 x i8]* %6, i64 0, i64 0
%50 = call i64 @stat(i8* %49, %struct.stat* %11)
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %60
52: ; preds = %40
%53 = load i32, i32* @stderr
%54 = load i8**, i8*** %5
%55 = getelementptr inbounds i8*, i8** %54, i64 0
%56 = load i8*, i8** %55
%57 = getelementptr inbounds [12 x i8], [12 x i8]* %6, i64 0, i64 0
%58 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %56, i8* %57)
%59 = call i32 @exit(i32 1)
unreachable
60: ; preds = %40
%61 = load %struct.passwd*, %struct.passwd** %7
%62 = getelementptr inbounds %struct.passwd, %struct.passwd* %61, i32 0, i32 0
%63 = load i64, i64* %62
%64 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%65 = load i64, i64* %64
%66 = icmp ne i64 %63, %65
br i1 %66, label %67, label %80
67: ; preds = %60
%68 = load i32, i32* @stderr
%69 = load i8**, i8*** %5
%70 = getelementptr inbounds i8*, i8** %69, i64 0
%71 = load i8*, i8** %70
%72 = load i8**, i8*** %5
%73 = getelementptr inbounds i8*, i8** %72, i64 1
%74 = load i8*, i8** %73
%75 = load i8**, i8*** %5
%76 = getelementptr inbounds i8*, i8** %75, i64 2
%77 = load i8*, i8** %76
%78 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8* %71, i8* %74, i8* %77)
%79 = call i32 @exit(i32 1)
unreachable
80: ; preds = %60
%81 = getelementptr inbounds [12 x i8], [12 x i8]* %6, i64 0, i64 0
%82 = load i32, i32* @O_WRONLY
%83 = call i32 @open(i8* %81, i32 %82)
store i32 %83, i32* %8
%84 = icmp slt i32 %83, 0
br i1 %84, label %85, label %98
85: ; preds = %80
%86 = load i32, i32* @stderr
%87 = load i8**, i8*** %5
%88 = getelementptr inbounds i8*, i8** %87, i64 0
%89 = load i8*, i8** %88
%90 = load i8**, i8*** %5
%91 = getelementptr inbounds i8*, i8** %90, i64 1
%92 = load i8*, i8** %91
%93 = load i8**, i8*** %5
%94 = getelementptr inbounds i8*, i8** %93, i64 2
%95 = load i8*, i8** %94
%96 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %86, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i8* %89, i8* %92, i8* %95)
%97 = call i32 @exit(i32 1)
unreachable
98: ; preds = %80
br label %149
99: ; preds = %37
%100 = call i32 (...) @setutent()
br label %101
101: ; preds = %134, %99
%102 = call %struct.utmp* (...) @getutent()
store %struct.utmp* %102, %struct.utmp** %12
%103 = icmp ne %struct.utmp* %102, null
br i1 %103, label %104, label %135
104: ; preds = %101
%105 = load %struct.passwd*, %struct.passwd** %7
%106 = getelementptr inbounds %struct.passwd, %struct.passwd* %105, i32 0, i32 1
%107 = load i8*, i8** %106
%108 = load %struct.utmp*, %struct.utmp** %12
%109 = getelementptr inbounds %struct.utmp, %struct.utmp* %108, i32 0, i32 2
%110 = load i32, i32* %109
%111 = call i64 @strcmp(i8* %107, i32 %110)
%112 = icmp eq i64 %111, 0
br i1 %112, label %113, label %134
113: ; preds = %104
%114 = load %struct.utmp*, %struct.utmp** %12
%115 = getelementptr inbounds %struct.utmp, %struct.utmp* %114, i32 0, i32 0
%116 = load i64, i64* %115
%117 = load i64, i64* @USER_PROCESS
%118 = icmp eq i64 %116, %117
br i1 %118, label %119, label %134
119: ; preds = %113
%120 = getelementptr inbounds [12 x i8], [12 x i8]* %6, i64 0, i64 0
%121 = call i32 @strncpy(i8* %120, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 6)
%122 = getelementptr inbounds [12 x i8], [12 x i8]* %6, i64 0, i64 0
%123 = load %struct.utmp*, %struct.utmp** %12
%124 = getelementptr inbounds %struct.utmp, %struct.utmp* %123, i32 0, i32 1
%125 = load i8*, i8** %124
%126 = call i32 @strncat(i8* %122, i8* %125, i32 6)
%127 = getelementptr inbounds [12 x i8], [12 x i8]* %6, i64 0, i64 11
store i8 0, i8* %127
%128 = getelementptr inbounds [12 x i8], [12 x i8]* %6, i64 0, i64 0
%129 = load i32, i32* @O_WRONLY
%130 = call i32 @open(i8* %128, i32 %129)
store i32 %130, i32* %8
%131 = icmp sge i32 %130, 0
br i1 %131, label %132, label %133
132: ; preds = %119
br label %135
133: ; preds = %119
br label %134
134: ; preds = %133, %113, %104
br label %101
135: ; preds = %132, %101
%136 = load i32, i32* %8
%137 = icmp slt i32 %136, 0
br i1 %137, label %138, label %148
138: ; preds = %135
%139 = load i32, i32* @stderr
%140 = load i8**, i8*** %5
%141 = getelementptr inbounds i8*, i8** %140, i64 0
%142 = load i8*, i8** %141
%143 = load i8**, i8*** %5
%144 = getelementptr inbounds i8*, i8** %143, i64 1
%145 = load i8*, i8** %144
%146 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %139, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.5, i64 0, i64 0), i8* %142, i8* %145)
%147 = call i32 @exit(i32 1)
unreachable
148: ; preds = %135
br label %149
149: ; preds = %148, %98
%150 = load i8**, i8*** %5
%151 = getelementptr inbounds i8*, i8** %150, i64 1
%152 = load i8*, i8** %151
%153 = call %struct.passwd* @getpwnam(i8* %152)
store %struct.passwd* %153, %struct.passwd** %7
%154 = icmp eq %struct.passwd* %153, null
br i1 %154, label %155, label %162
155: ; preds = %149
%156 = load i32, i32* @stderr
%157 = load i8**, i8*** %5
%158 = getelementptr inbounds i8*, i8** %157, i64 0
%159 = load i8*, i8** %158
%160 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %156, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i8* %159)
%161 = call i32 @exit(i32 1)
unreachable
162: ; preds = %149
%163 = load i32, i32* %8
%164 = call i32 @write(i32 %163, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i32 13)
%165 = load i32, i32* %8
%166 = load %struct.passwd*, %struct.passwd** %7
%167 = getelementptr inbounds %struct.passwd, %struct.passwd* %166, i32 0, i32 1
%168 = load i8*, i8** %167
%169 = load %struct.passwd*, %struct.passwd** %7
%170 = getelementptr inbounds %struct.passwd, %struct.passwd* %169, i32 0, i32 1
%171 = load i8*, i8** %170
%172 = call i32 @strlen(i8* %171)
%173 = call i32 @write(i32 %165, i8* %168, i32 %172)
%174 = load i32, i32* %8
%175 = call i32 @write(i32 %174, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i32 1)
br label %176
176: ; preds = %181, %162
%177 = load i32, i32* @STDIN_FILENO
%178 = getelementptr inbounds [255 x i8], [255 x i8]* %9, i64 0, i64 0
%179 = call i32 @read(i32 %177, i8* %178, i32 254)
store i32 %179, i32* %10
%180 = icmp sgt i32 %179, 0
br i1 %180, label %181, label %187
181: ; preds = %176
%182 = getelementptr inbounds [255 x i8], [255 x i8]* %9, i64 0, i64 254
store i8 0, i8* %182
%183 = load i32, i32* %8
%184 = getelementptr inbounds [255 x i8], [255 x i8]* %9, i64 0, i64 0
%185 = load i32, i32* %10
%186 = call i32 @write(i32 %183, i8* %184, i32 %185)
br label %176
187: ; preds = %176
%188 = load i32, i32* %8
%189 = call i32 @write(i32 %188, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i32 4)
%190 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.stat = type { i64 }
%struct.passwd = type { i64, i8* }
%struct.utmp = type { i64, i8*, i32 }
@stderr = global i32 0
@.str = [21 x i8] c"%s: No such user %s\0A\00"
@.str.1 = [6 x i8] c"/dev/\00"
@.str.2 = [20 x i8] c"%s: No such tty %s\0A\00"
@.str.3 = [35 x i8] c"%s: User %s is not logged onto %s\0A\00"
@O_WRONLY = global i32 0
@.str.4 = [36 x i8] c"%s: %s has messages disabled on %s\0A\00"
@USER_PROCESS = global i64 0
@.str.5 = [53 x i8] c"%s: User %s not logged in, or has messages disabled\0A\00"
@.str.6 = [18 x i8] c"%s: Who are you?\0A\00"
@.str.7 = [14 x i8] c"Message from \00"
@.str.8 = [2 x i8] c"\0A\00"
@STDIN_FILENO = global i32 0
@.str.9 = [5 x i8] c"EOF\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [12 x i8]
%4 = alloca [255 x i8]
%5 = alloca %struct.stat
%6 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%8 = add i32 %0, -4
%9 = icmp ult i32 %8, -2
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = tail call i32 @usage(i8** %1)
br label %12
12: ; preds = %2, %10
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call %struct.passwd* @getpwnam(i8* %14)
%16 = icmp eq %struct.passwd* %15, null
br i1 %16, label %17, label %23
17: ; preds = %12
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %1
%20 = load i8*, i8** %13
%21 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %19, i8* %20)
%22 = tail call i32 @exit(i32 1)
unreachable
23: ; preds = %12
%24 = icmp eq i32 %0, 3
br i1 %24, label %25, label %64
25: ; preds = %23
%26 = bitcast %struct.stat* %5 to i8*
%27 = call i32 @strncpy(i8* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 6)
%28 = getelementptr inbounds i8*, i8** %1, i64 2
%29 = load i8*, i8** %28
%30 = call i32 @strncat(i8* %6, i8* %29, i32 6)
%31 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 11
store i8 0, i8* %31
%32 = call i64 @stat(i8* %6, %struct.stat* %5)
%33 = icmp eq i64 %32, 0
br i1 %33, label %39, label %34
34: ; preds = %25
%35 = load i32, i32* @stderr
%36 = load i8*, i8** %1
%37 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %36, i8* %6)
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %25
%40 = getelementptr inbounds %struct.passwd, %struct.passwd* %15, i64 0, i32 0
%41 = load i64, i64* %40
%42 = getelementptr inbounds %struct.stat, %struct.stat* %5, i64 0, i32 0
%43 = load i64, i64* %42
%44 = icmp eq i64 %41, %43
br i1 %44, label %52, label %45
45: ; preds = %39
%46 = load i32, i32* @stderr
%47 = load i8*, i8** %1
%48 = load i8*, i8** %13
%49 = load i8*, i8** %28
%50 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8* %47, i8* %48, i8* %49)
%51 = call i32 @exit(i32 1)
unreachable
52: ; preds = %39
%53 = load i32, i32* @O_WRONLY
%54 = call i32 @open(i8* %6, i32 %53)
%55 = icmp slt i32 %54, 0
br i1 %55, label %56, label %63
56: ; preds = %52
%57 = load i32, i32* @stderr
%58 = load i8*, i8** %1
%59 = load i8*, i8** %13
%60 = load i8*, i8** %28
%61 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i8* %58, i8* %59, i8* %60)
%62 = call i32 @exit(i32 1)
unreachable
63: ; preds = %52
br label %104
64: ; preds = %23
%65 = tail call i32 (...) @setutent()
%66 = call %struct.utmp* (...) @getutent()
%67 = icmp eq %struct.utmp* %66, null
br i1 %67, label %98, label %68
68: ; preds = %64
%69 = getelementptr inbounds %struct.passwd, %struct.passwd* %15, i64 0, i32 1
%70 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 11
br label %71
71: ; preds = %68, %92
%72 = phi %struct.utmp* [ %66, %68 ], [ %94, %92 ]
%73 = phi i32 [ -1, %68 ], [ %93, %92 ]
%74 = load i8*, i8** %69
%75 = getelementptr inbounds %struct.utmp, %struct.utmp* %72, i64 0, i32 2
%76 = load i32, i32* %75
%77 = call i64 @strcmp(i8* %74, i32 %76)
%78 = icmp eq i64 %77, 0
br i1 %78, label %79, label %92
79: ; preds = %71
%80 = getelementptr inbounds %struct.utmp, %struct.utmp* %72, i64 0, i32 0
%81 = load i64, i64* %80
%82 = load i64, i64* @USER_PROCESS
%83 = icmp eq i64 %81, %82
br i1 %83, label %84, label %92
84: ; preds = %79
%85 = call i32 @strncpy(i8* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 6)
%86 = getelementptr inbounds %struct.utmp, %struct.utmp* %72, i64 0, i32 1
%87 = load i8*, i8** %86
%88 = call i32 @strncat(i8* %6, i8* %87, i32 6)
store i8 0, i8* %70
%89 = load i32, i32* @O_WRONLY
%90 = call i32 @open(i8* %6, i32 %89)
%91 = icmp sgt i32 %90, -1
br i1 %91, label %104, label %92
92: ; preds = %84, %79, %71
%93 = phi i32 [ %90, %84 ], [ %73, %79 ], [ %73, %71 ]
%94 = call %struct.utmp* (...) @getutent()
%95 = icmp eq %struct.utmp* %94, null
br i1 %95, label %96, label %71
96: ; preds = %92
%97 = icmp slt i32 %93, 0
br i1 %97, label %98, label %104
98: ; preds = %64, %96
%99 = load i32, i32* @stderr
%100 = load i8*, i8** %1
%101 = load i8*, i8** %13
%102 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %99, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.5, i64 0, i64 0), i8* %100, i8* %101)
%103 = call i32 @exit(i32 1)
unreachable
104: ; preds = %84, %96, %63
%105 = phi i32 [ %54, %63 ], [ %93, %96 ], [ %90, %84 ]
%106 = load i8*, i8** %13
%107 = call %struct.passwd* @getpwnam(i8* %106)
%108 = icmp eq %struct.passwd* %107, null
br i1 %108, label %109, label %114
109: ; preds = %104
%110 = load i32, i32* @stderr
%111 = load i8*, i8** %1
%112 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %110, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i8* %111)
%113 = call i32 @exit(i32 1)
unreachable
114: ; preds = %104
%115 = call i32 @write(i32 %105, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i32 13)
%116 = getelementptr inbounds %struct.passwd, %struct.passwd* %107, i64 0, i32 1
%117 = load i8*, i8** %116
%118 = call i32 @strlen(i8* %117)
%119 = call i32 @write(i32 %105, i8* %117, i32 %118)
%120 = call i32 @write(i32 %105, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i32 1)
%121 = load i32, i32* @STDIN_FILENO
%122 = call i32 @read(i32 %121, i8* %7, i32 254)
%123 = icmp sgt i32 %122, 0
br i1 %123, label %124, label %132
124: ; preds = %114
%125 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 254
br label %126
126: ; preds = %124, %126
%127 = phi i32 [ %122, %124 ], [ %130, %126 ]
store i8 0, i8* %125
%128 = call i32 @write(i32 %105, i8* %7, i32 %127)
%129 = load i32, i32* @STDIN_FILENO
%130 = call i32 @read(i32 %129, i8* %7, i32 254)
%131 = icmp sgt i32 %130, 0
br i1 %131, label %126, label %132
132: ; preds = %126, %114
%133 = call i32 @write(i32 %105, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i32 4)
%134 = call i32 @exit(i32 0)
unreachable
}