#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();
scalar_t__ strcmp(int /*<<< orphan*/, char const *);
struct ttyent *getttynam(const char *name) {
  struct ttyent *tty;
  endttyent();
  while ((tty = getttyent()) != 0 && strcmp(tty->ty_name, name) != 0) {
  }
  endttyent();
  return tty;
}


x86 assembly (clang, -O0):
<getttynam>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1030 <endttyent@plt>
mov    $0x0,%al
call   1040 <getttyent@plt>
mov    %rax,%rcx
mov    %rcx,-0x10(%rbp)
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x11(%rbp)
je     1179 <getttynam+0x49>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1189 <getttynam+0x59>
jmp    118e <getttynam+0x5e>
jmp    1143 <getttynam+0x13>
mov    $0x0,%al
call   1030 <endttyent@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getttynam>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %eax,%eax
call   1030 <endttyent@plt>
xchg   %ax,%ax
xor    %eax,%eax
call   1040 <getttyent@plt>
mov    %rax,%rbx
test   %rax,%rax
je     115e <getttynam+0x2e>
mov    (%rbx),%edi
mov    %r14,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    1140 <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 (...) @endttyent()
br label %5
5: ; preds = %17, %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 %15
8: ; preds = %5
%9 = load %struct.ttyent*, %struct.ttyent** %3
%10 = getelementptr inbounds %struct.ttyent, %struct.ttyent* %9, i32 0, i32 0
%11 = load i32, i32* %10
%12 = load i8*, i8** %2
%13 = call i64 @strcmp(i32 %11, i8* %12)
%14 = icmp ne i64 %13, 0
br label %15
15: ; preds = %8, %5
%16 = phi i1 [ false, %5 ], [ %14, %8 ]
br i1 %16, label %17, label %18
17: ; preds = %15
br label %5
18: ; preds = %15
%19 = call i32 (...) @endttyent()
%20 = load %struct.ttyent*, %struct.ttyent** %3
ret %struct.ttyent* %20
}

LLVM IR (-O2):
%struct.ttyent = type { i32 }
define %struct.ttyent* @getttynam(i8* %0) {
%2 = tail call i32 (...) @endttyent()
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 i64 @strcmp(i32 %8, i8* %0)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %3
11: ; preds = %3, %6
%12 = tail call i32 (...) @endttyent()
ret %struct.ttyent* %4
}