#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 ttyent {
  int /*<<< orphan*/ ty_name;
};

/* Variables and functions */
int /*<<< orphan*/ __endttyent();
struct ttyent *__getttyent();
int /*<<< orphan*/ __setttyent();
int /*<<< orphan*/ strcmp(char const *, int /*<<< orphan*/);
struct ttyent *__getttynam(const char *tty) {
  struct ttyent *t;
  __setttyent();
  while ((t = __getttyent()))
    if (!strcmp(tty, t->ty_name))
      break;
  __endttyent();
  return (t);
}


x86 assembly (clang, -O0):
<__getttynam>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1040 <__setttyent@plt>
mov    $0x0,%al
call   1060 <__getttyent@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     118a <__getttynam+0x4a>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    1185 <__getttynam+0x45>
jmp    118a <__getttynam+0x4a>
jmp    1153 <__getttynam+0x13>
mov    $0x0,%al
call   1030 <__endttyent@plt>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__getttynam>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %eax,%eax
call   1040 <__setttyent@plt>
xchg   %ax,%ax
xor    %eax,%eax
call   1060 <__getttyent@plt>
mov    %rax,%rbx
test   %rax,%rax
je     116d <__getttynam+0x2d>
mov    (%rbx),%esi
mov    %r14,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
jne    1150 <__getttynam+0x10>
xor    %eax,%eax
call   1030 <__endttyent@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.ttyent = type { i32 }
define %struct.ttyent* @__getttynam(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.ttyent*
store i8* %0, i8** %2
%4 = call i32 (...) @__setttyent()
br label %5
5: ; preds = %16, %1
%6 = call %struct.ttyent* (...) @__getttyent()
store %struct.ttyent* %6, %struct.ttyent** %3
%7 = icmp ne %struct.ttyent* %6, null
br i1 %7, label %8, label %17
8: ; preds = %5
%9 = load i8*, i8** %2
%10 = load %struct.ttyent*, %struct.ttyent** %3
%11 = getelementptr inbounds %struct.ttyent, %struct.ttyent* %10, i32 0, i32 0
%12 = load i32, i32* %11
%13 = call i32 @strcmp(i8* %9, i32 %12)
%14 = icmp ne i32 %13, 0
br i1 %14, label %16, label %15
15: ; preds = %8
br label %17
16: ; preds = %8
br label %5
17: ; preds = %15, %5
%18 = call i32 (...) @__endttyent()
%19 = load %struct.ttyent*, %struct.ttyent** %3
ret %struct.ttyent* %19
}

LLVM IR (-O2):
%struct.ttyent = type { i32 }
define %struct.ttyent* @__getttynam(i8* %0) {
%2 = tail call i32 (...) @__setttyent()
br label %3
3: ; preds = %6, %1
%4 = tail call %struct.ttyent* (...) @__getttyent()
%5 = icmp eq %struct.ttyent* %4, null
br i1 %5, label %11, label %6
6: ; preds = %3
%7 = getelementptr inbounds %struct.ttyent, %struct.ttyent* %4, i64 0, i32 0
%8 = load i32, i32* %7
%9 = tail call i32 @strcmp(i8* %0, i32 %8)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %3
11: ; preds = %6, %3
%12 = tail call i32 (...) @__endttyent()
ret %struct.ttyent* %4
}