#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*/ ttybuf;
struct stat {
  int dummy;
};

/* Variables and functions */
int MAXPATHLEN;
char *_PATH_DEV;
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
scalar_t__ stat(char *, struct stat *);
int ttystat(char *line) {
  struct stat sb;
  char ttybuf[MAXPATHLEN];
  (void)snprintf(ttybuf, sizeof(ttybuf), "%s%s", _PATH_DEV, line);
  if (stat(ttybuf, &sb) == 0) {
    return (0);
  } else
    return (-1);
}


x86 assembly (clang, -O0):
<ttystat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2ead(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
mov    %eax,%esi
mov    0x2e87(%rip),%rax
mov    (%rax),%rcx
mov    -0x10(%rbp),%r8
lea    0xe91(%rip),%rdx
call   1030 <snprintf@plt>
mov    -0x38(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0x0,%rax
jne    119e <ttystat+0x7e>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    11ac <ttystat+0x8c>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ttystat>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r8
mov    %rsp,%r14
mov    0x2ea8(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rbx
mov    %rsi,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    0x2e93(%rip),%rax
mov    (%rax),%rcx
lea    0xea1(%rip),%rdx
mov    %rbx,%rdi
call   1030 <snprintf@plt>
lea    -0x18(%rbp),%rsi
mov    %rbx,%rdi
call   1040 <stat@plt>
neg    %rax
sbb    %eax,%eax
mov    %r14,%rsp
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@MAXPATHLEN = global i32 0
@.str = [5 x i8] c"%s%s\00"
@_PATH_DEV = global i8* null
define i32 @ttystat(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.stat
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
store i8* %0, i8** %3
%8 = load i32, i32* @MAXPATHLEN
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %5
%11 = alloca i8, i64 %9
store i64 %9, i64* %6
%12 = trunc i64 %9 to i32
%13 = load i8*, i8** @_PATH_DEV
%14 = load i8*, i8** %3
%15 = call i32 @snprintf(i8* %11, i32 %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %13, i8* %14)
%16 = call i64 @stat(i8* %11, %struct.stat* %4)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %1
store i32 0, i32* %2
store i32 1, i32* %7
br label %20
19: ; preds = %1
store i32 -1, i32* %2
store i32 1, i32* %7
br label %20
20: ; preds = %19, %18
%21 = load i8*, i8** %5
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@MAXPATHLEN = global i32 0
@.str = [5 x i8] c"%s%s\00"
@_PATH_DEV = global i8* null
define i32 @ttystat(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = load i32, i32* @MAXPATHLEN
%5 = zext i32 %4 to i64
%6 = tail call i8* @llvm.stacksave()
%7 = alloca i8, i64 %5
%8 = load i8*, i8** @_PATH_DEV
%9 = call i32 @snprintf(i8* %7, i32 %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %8, i8* %0)
%10 = call i64 @stat(i8* %7, %struct.stat* %2)
%11 = icmp ne i64 %10, 0
%12 = sext i1 %11 to i32
ret i32 %12
}