#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 utmp {
  scalar_t__ ut_type;
  int /*<<< orphan*/ ut_line;
};

/* Variables and functions */
scalar_t__ LOGIN_PROCESS;
scalar_t__ USER_PROCESS;
struct utmp *getutent();
int /*<<< orphan*/ strcmp(int /*<<< orphan*/, int /*<<< orphan*/);
struct utmp *getutline(const struct utmp *utmp_entry) {
  struct utmp *utmp;
  while ((utmp = getutent()) != NULL) {
    if ((utmp->ut_type == USER_PROCESS || utmp->ut_type == LOGIN_PROCESS) &&
        !strcmp(utmp->ut_line, utmp_entry->ut_line))
      return utmp;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<getutline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1040 <getutent@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     119d <getutline+0x7d>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    0x2e99(%rip),%rcx
cmp    (%rcx),%rax
je     116f <getutline+0x4f>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    0x2e6a(%rip),%rcx
cmp    (%rcx),%rax
jne    1198 <getutline+0x78>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%esi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    1198 <getutline+0x78>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11a5 <getutline+0x85>
jmp    112c <getutline+0xc>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getutline>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <getutent@plt>
test   %rax,%rax
je     1181 <getutline+0x61>
mov    0x2ea8(%rip),%r15
mov    0x2e89(%rip),%r12
mov    %rax,%rbx
jmp    116f <getutline+0x4f>
nopl   0x0(%rax)
mov    0x8(%rbx),%edi
mov    0x8(%r14),%esi
call   1030 <strcmp@plt>
test   %eax,%eax
je     1181 <getutline+0x61>
xor    %eax,%eax
call   1040 <getutent@plt>
mov    %rax,%rbx
test   %rax,%rax
je     117f <getutline+0x5f>
mov    (%rbx),%rax
cmp    (%r15),%rax
je     1150 <getutline+0x30>
cmp    (%r12),%rax
jne    1160 <getutline+0x40>
jmp    1150 <getutline+0x30>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.utmp = type { i64, i32 }
@USER_PROCESS = global i64 0
@LOGIN_PROCESS = global i64 0
define %struct.utmp* @getutline(%struct.utmp* %0) {
%2 = alloca %struct.utmp*
%3 = alloca %struct.utmp*
%4 = alloca %struct.utmp*
store %struct.utmp* %0, %struct.utmp** %3
br label %5
5: ; preds = %31, %1
%6 = call %struct.utmp* (...) @getutent()
store %struct.utmp* %6, %struct.utmp** %4
%7 = icmp ne %struct.utmp* %6, null
br i1 %7, label %8, label %32
8: ; preds = %5
%9 = load %struct.utmp*, %struct.utmp** %4
%10 = getelementptr inbounds %struct.utmp, %struct.utmp* %9, i32 0, i32 0
%11 = load i64, i64* %10
%12 = load i64, i64* @USER_PROCESS
%13 = icmp eq i64 %11, %12
br i1 %13, label %20, label %14
14: ; preds = %8
%15 = load %struct.utmp*, %struct.utmp** %4
%16 = getelementptr inbounds %struct.utmp, %struct.utmp* %15, i32 0, i32 0
%17 = load i64, i64* %16
%18 = load i64, i64* @LOGIN_PROCESS
%19 = icmp eq i64 %17, %18
br i1 %19, label %20, label %31
20: ; preds = %14, %8
%21 = load %struct.utmp*, %struct.utmp** %4
%22 = getelementptr inbounds %struct.utmp, %struct.utmp* %21, i32 0, i32 1
%23 = load i32, i32* %22
%24 = load %struct.utmp*, %struct.utmp** %3
%25 = getelementptr inbounds %struct.utmp, %struct.utmp* %24, i32 0, i32 1
%26 = load i32, i32* %25
%27 = call i32 @strcmp(i32 %23, i32 %26)
%28 = icmp ne i32 %27, 0
br i1 %28, label %31, label %29
29: ; preds = %20
%30 = load %struct.utmp*, %struct.utmp** %4
store %struct.utmp* %30, %struct.utmp** %2
br label %33
31: ; preds = %20, %14
br label %5
32: ; preds = %5
store %struct.utmp* null, %struct.utmp** %2
br label %33
33: ; preds = %32, %29
%34 = load %struct.utmp*, %struct.utmp** %2
ret %struct.utmp* %34
}

LLVM IR (-O2):
%struct.utmp = type { i64, i32 }
@USER_PROCESS = global i64 0
@LOGIN_PROCESS = global i64 0
define %struct.utmp* @getutline(%struct.utmp* nocapture %0) {
%2 = tail call %struct.utmp* (...) @getutent()
%3 = icmp eq %struct.utmp* %2, null
br i1 %3, label %24, label %4
4: ; preds = %1
%5 = getelementptr inbounds %struct.utmp, %struct.utmp* %0, i64 0, i32 1
br label %6
6: ; preds = %4, %21
%7 = phi %struct.utmp* [ %2, %4 ], [ %22, %21 ]
%8 = getelementptr inbounds %struct.utmp, %struct.utmp* %7, i64 0, i32 0
%9 = load i64, i64* %8
%10 = load i64, i64* @USER_PROCESS
%11 = icmp eq i64 %9, %10
%12 = load i64, i64* @LOGIN_PROCESS
%13 = icmp eq i64 %9, %12
%14 = select i1 %11, i1 true, i1 %13
br i1 %14, label %15, label %21
15: ; preds = %6
%16 = getelementptr inbounds %struct.utmp, %struct.utmp* %7, i64 0, i32 1
%17 = load i32, i32* %16
%18 = load i32, i32* %5
%19 = tail call i32 @strcmp(i32 %17, i32 %18)
%20 = icmp eq i32 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %6, %15
%22 = tail call %struct.utmp* (...) @getutent()
%23 = icmp eq %struct.utmp* %22, null
br i1 %23, label %24, label %6
24: ; preds = %15, %21, %1
%25 = phi %struct.utmp* [ null, %1 ], [ null, %21 ], [ %7, %15 ]
ret %struct.utmp* %25
}