#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(char *, int /*<<< orphan*/);
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(("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    1221 <ttyconv+0xb1>
mov    $0x8,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11c5 <ttyconv+0x55>
mov    0x2e33(%rip),%rax
mov    (%rax),%esi
lea    0xe4a(%rip),%rdi
call   1060 <fputs@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rdi
lea    0xe47(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    11f3 <ttyconv+0x83>
mov    -0x18(%rbp),%rdi
lea    0xe31(%rip),%rsi
call   1040 <strcpy@plt>
jmp    1214 <ttyconv+0xa4>
mov    -0x18(%rbp),%rdi
lea    0xe24(%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    1258 <ttyconv+0xe8>
mov    -0x10(%rbp),%rdi
lea    0xdfa(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1250 <ttyconv+0xe0>
mov    -0x10(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x8(%rbp)
jmp    1258 <ttyconv+0xe8>
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    11c1 <ttyconv+0x51>
mov    $0x8,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     11ff <ttyconv+0x8f>
mov    %rax,%rbx
lea    0xe7d(%rip),%rsi
mov    %r14,%rdi
call   1070 <strcmp@plt>
test   %eax,%eax
je     11e5 <ttyconv+0x75>
lea    0xe75(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
add    $0x3,%rdi
mov    %r14,%rsi
jmp    11ef <ttyconv+0x7f>
lea    0xe5e(%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    11f4 <ttyconv+0x84>
lea    0xe2e(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcpy@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2dda(%rip),%rax
mov    (%rax),%esi
lea    0xdf1(%rip),%rdi
call   1060 <fputs@plt>
mov    $0x1,%edi
call   1090 <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 %31
8: ; preds = %1
%9 = call i8* @malloc(i32 8)
store i8* %9, i8** %4
%10 = icmp ne i8* %9, null
br i1 %10, label %15, label %11
11: ; preds = %8
%12 = load i32, i32* @stderr
%13 = call i32 @fputs(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %8
%16 = load i8*, i8** %3
%17 = call i32 @strcmp(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp ne i32 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %15
%20 = load i8*, i8** %4
%21 = call i32 @strcpy(i8* %20, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %29
22: ; preds = %15
%23 = load i8*, i8** %4
%24 = call i32 @strcpy(i8* %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%25 = load i8*, i8** %4
%26 = getelementptr inbounds i8, i8* %25, i64 3
%27 = load i8*, i8** %3
%28 = call i32 @strcpy(i8* %26, i8* %27)
br label %29
29: ; preds = %22, %19
%30 = load i8*, i8** %4
store i8* %30, i8** %2
br label %40
31: ; preds = %1
%32 = load i8*, i8** %3
%33 = call i32 @strncmp(i8* %32, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 5)
%34 = icmp ne i32 %33, 0
br i1 %34, label %38, label %35
35: ; preds = %31
%36 = load i8*, i8** %3
%37 = getelementptr inbounds i8, i8* %36, i64 5
store i8* %37, i8** %2
br label %40
38: ; preds = %31
%39 = load i8*, i8** %3
store i8* %39, i8** %2
br label %40
40: ; preds = %38, %35, %29
%41 = load i8*, i8** %2
ret i8* %41
}

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 %20
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 %11
7: ; preds = %4
%8 = load i32, i32* @stderr
%9 = tail call i32 @fputs(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %4
%12 = 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))
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = tail call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %25
16: ; preds = %11
%17 = tail call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%18 = getelementptr inbounds i8, i8* %5, i64 3
%19 = tail call i32 @strcpy(i8* %18, i8* %0)
br label %25
20: ; preds = %1
%21 = tail call i32 @strncmp(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 5)
%22 = icmp eq i32 %21, 0
%23 = select i1 %22, i64 5, i64 0
%24 = getelementptr i8, i8* %0, i64 %23
br label %25
25: ; preds = %20, %14, %16
%26 = phi i8* [ %5, %16 ], [ %5, %14 ], [ %24, %20 ]
ret i8* %26
}