#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*/ exit(int);
int /*<<< orphan*/ fputs(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ gettext(char *);
char *malloc(unsigned int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
char *ttyconv(char *arg) {
  char *mval;
  if (strlen(arg) == 2) {
    if (!(mval = malloc((unsigned int)8))) {
      fputs(gettext("last: malloc failure.\n"), stderr);
      exit(1);
    }
    if (!strcmp(arg, "co"))
      (void)strcpy(mval, "console");
    else {
      (void)strcpy(mval, "tty");
      (void)strcpy(mval + 3, arg);
    }
    return (mval);
  }
  if (!strncmp(arg, "/dev/", sizeof("/dev/") - 1))
    return (arg + 5);
  return (arg);
}


x86 assembly (clang, -O0):
<ttyconv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x2,%eax
jne    1238 <ttyconv+0xb8>
mov    $0x8,%edi
call   1090 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11dc <ttyconv+0x5c>
lea    0xe43(%rip),%rdi
call   1060 <gettext@plt>
mov    %eax,%edi
mov    0x2e15(%rip),%rax
mov    (%rax),%esi
call   1070 <fputs@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rdi
lea    0xe30(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    120a <ttyconv+0x8a>
mov    -0x18(%rbp),%rdi
lea    0xe1a(%rip),%rsi
call   1040 <strcpy@plt>
jmp    122b <ttyconv+0xab>
mov    -0x18(%rbp),%rdi
lea    0xe0d(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rdi
add    $0x3,%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    126f <ttyconv+0xef>
mov    -0x10(%rbp),%rdi
lea    0xde3(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1267 <ttyconv+0xe7>
mov    -0x10(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x8(%rbp)
jmp    126f <ttyconv+0xef>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ttyconv>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1050 <strlen@plt>
cmp    $0x2,%eax
jne    11d1 <ttyconv+0x51>
mov    $0x8,%edi
call   1090 <malloc@plt>
test   %rax,%rax
je     120f <ttyconv+0x8f>
mov    %rax,%rbx
lea    0xe6d(%rip),%rsi
mov    %r14,%rdi
call   1080 <strcmp@plt>
test   %eax,%eax
je     11f5 <ttyconv+0x75>
lea    0xe65(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
add    $0x3,%rdi
mov    %r14,%rsi
jmp    11ff <ttyconv+0x7f>
lea    0xe4e(%rip),%rsi
mov    %r14,%rdi
mov    $0x5,%edx
call   1030 <strncmp@plt>
xor    %ecx,%ecx
test   %eax,%eax
sete   %cl
lea    (%rcx,%rcx,4),%rbx
add    %r14,%rbx
jmp    1204 <ttyconv+0x84>
lea    0xe1e(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcpy@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xdea(%rip),%rdi
call   1060 <gettext@plt>
mov    0x2dbe(%rip),%rcx
mov    (%rcx),%esi
mov    %eax,%edi
call   1070 <fputs@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [23 x i8] c"last: malloc failure.\0A\00"
@stderr = global i32 0
@.str.1 = [3 x i8] c"co\00"
@.str.2 = [8 x i8] c"console\00"
@.str.3 = [4 x i8] c"tty\00"
@.str.4 = [6 x i8] c"/dev/\00"
define i8* @ttyconv(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i32 @strlen(i8* %5)
%7 = icmp eq i32 %6, 2
br i1 %7, label %8, label %32
8: ; preds = %1
%9 = call i8* @malloc(i32 8)
store i8* %9, i8** %4
%10 = icmp ne i8* %9, null
br i1 %10, label %16, label %11
11: ; preds = %8
%12 = call i32 @gettext(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @stderr
%14 = call i32 @fputs(i32 %12, i32 %13)
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %8
%17 = load i8*, i8** %3
%18 = call i32 @strcmp(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp ne i32 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %16
%21 = load i8*, i8** %4
%22 = call i32 @strcpy(i8* %21, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %30
23: ; preds = %16
%24 = load i8*, i8** %4
%25 = call i32 @strcpy(i8* %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%26 = load i8*, i8** %4
%27 = getelementptr inbounds i8, i8* %26, i64 3
%28 = load i8*, i8** %3
%29 = call i32 @strcpy(i8* %27, i8* %28)
br label %30
30: ; preds = %23, %20
%31 = load i8*, i8** %4
store i8* %31, i8** %2
br label %41
32: ; preds = %1
%33 = load i8*, i8** %3
%34 = call i32 @strncmp(i8* %33, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 5)
%35 = icmp ne i32 %34, 0
br i1 %35, label %39, label %36
36: ; preds = %32
%37 = load i8*, i8** %3
%38 = getelementptr inbounds i8, i8* %37, i64 5
store i8* %38, i8** %2
br label %41
39: ; preds = %32
%40 = load i8*, i8** %3
store i8* %40, i8** %2
br label %41
41: ; preds = %39, %36, %30
%42 = load i8*, i8** %2
ret i8* %42
}

LLVM IR (-O2):
@.str = [23 x i8] c"last: malloc failure.\0A\00"
@stderr = global i32 0
@.str.1 = [3 x i8] c"co\00"
@.str.2 = [8 x i8] c"console\00"
@.str.3 = [4 x i8] c"tty\00"
@.str.4 = [6 x i8] c"/dev/\00"
define i8* @ttyconv(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp eq i32 %2, 2
br i1 %3, label %4, label %21
4: ; preds = %1
%5 = tail call dereferenceable_or_null(8) i8* @malloc(i32 8)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %12
7: ; preds = %4
%8 = tail call i32 @gettext(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @stderr
%10 = tail call i32 @fputs(i32 %8, i32 %9)
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %4
%13 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = tail call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %26
17: ; preds = %12
%18 = tail call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%19 = getelementptr inbounds i8, i8* %5, i64 3
%20 = tail call i32 @strcpy(i8* %19, i8* %0)
br label %26
21: ; preds = %1
%22 = tail call i32 @strncmp(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 5)
%23 = icmp eq i32 %22, 0
%24 = select i1 %23, i64 5, i64 0
%25 = getelementptr i8, i8* %0, i64 %24
br label %26
26: ; preds = %21, %15, %17
%27 = phi i8* [ %5, %17 ], [ %5, %15 ], [ %25, %21 ]
ret i8* %27
}