#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 utmpx {
  int ut_type;
  int /*<<< orphan*/ ut_id;
};

/* Variables and functions */
#define DEAD_PROCESS 131
#define INIT_PROCESS 130
#define LOGIN_PROCESS 129
#define USER_PROCESS 128
struct utmpx *__getutxent();
int /*<<< orphan*/ strncmp(int /*<<< orphan*/, int /*<<< orphan*/, int);
struct utmpx *getutxid(const struct utmpx *id) {
  switch (id->ut_type) {
  case INIT_PROCESS:
  case LOGIN_PROCESS:
  case USER_PROCESS:
  case DEAD_PROCESS:
    for (;;) {
      struct utmpx *next = __getutxent();
      if (next == NULL)
        return NULL;
      switch (next->ut_type) {
      case INIT_PROCESS:
      case LOGIN_PROCESS:
      case USER_PROCESS:
      case DEAD_PROCESS:
        if (strncmp(next->ut_id, id->ut_id, sizeof(id->ut_id)) == 0)
          return next;
        break;
      default:
        break;
      }
    }
  default:
    for (;;) {
      struct utmpx *next = __getutxent();
      if (next == NULL)
        return NULL;
      if (next->ut_type == id->ut_type)
        return next;
    }
  }
}


x86 assembly (clang, -O0):
<getutxid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
add    $0xffffff80,%eax
sub    $0x3,%eax
ja     11bf <getutxid+0x9f>
jmp    1143 <getutxid+0x23>
jmp    1148 <getutxid+0x28>
mov    $0x0,%al
call   1040 <__getutxent@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    116b <getutxid+0x4b>
movq   $0x0,-0x8(%rbp)
jmp    120b <getutxid+0xeb>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
add    $0xffffff80,%eax
sub    $0x3,%eax
ja     11b5 <getutxid+0x95>
jmp    1182 <getutxid+0x62>
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%esi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    11b0 <getutxid+0x90>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    120b <getutxid+0xeb>
jmp    11ba <getutxid+0x9a>
jmp    11ba <getutxid+0x9a>
jmp    1148 <getutxid+0x28>
jmp    11c4 <getutxid+0xa4>
mov    $0x0,%al
call   1040 <__getutxent@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11e7 <getutxid+0xc7>
movq   $0x0,-0x8(%rbp)
jmp    120b <getutxid+0xeb>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jne    1206 <getutxid+0xe6>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    120b <getutxid+0xeb>
jmp    11c4 <getutxid+0xa4>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getutxid>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    (%rdi),%eax
and    $0xfffffffc,%eax
cmp    $0x80,%eax
jne    1150 <getutxid+0x30>
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <__getutxent@plt>
test   %rax,%rax
je     11a4 <getutxid+0x84>
mov    %rax,%rbx
jmp    117f <getutxid+0x5f>
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <__getutxent@plt>
test   %rax,%rax
je     11a2 <getutxid+0x82>
mov    %rax,%rbx
mov    (%rax),%eax
cmp    (%r14),%eax
jne    1150 <getutxid+0x30>
jmp    11a4 <getutxid+0x84>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <__getutxent@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11a2 <getutxid+0x82>
mov    (%rbx),%eax
and    $0xfffffffc,%eax
cmp    $0x80,%eax
jne    1170 <getutxid+0x50>
mov    0x4(%rbx),%edi
mov    0x4(%r14),%esi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    1170 <getutxid+0x50>
jmp    11a4 <getutxid+0x84>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.utmpx = type { i32, i32 }
define %struct.utmpx* @getutxid(%struct.utmpx* %0) {
%2 = alloca %struct.utmpx*
%3 = alloca %struct.utmpx*
%4 = alloca %struct.utmpx*
%5 = alloca %struct.utmpx*
store %struct.utmpx* %0, %struct.utmpx** %3
%6 = load %struct.utmpx*, %struct.utmpx** %3
%7 = getelementptr inbounds %struct.utmpx, %struct.utmpx* %6, i32 0, i32 0
%8 = load i32, i32* %7
switch i32 %8, label %33 [
i32 130, label %9
i32 129, label %9
i32 128, label %9
i32 131, label %9
]
9: ; preds = %1, %1, %1, %1
br label %10
10: ; preds = %32, %9
%11 = call %struct.utmpx* (...) @__getutxent()
store %struct.utmpx* %11, %struct.utmpx** %4
%12 = load %struct.utmpx*, %struct.utmpx** %4
%13 = icmp eq %struct.utmpx* %12, null
br i1 %13, label %14, label %15
14: ; preds = %10
store %struct.utmpx* null, %struct.utmpx** %2
br label %50
15: ; preds = %10
%16 = load %struct.utmpx*, %struct.utmpx** %4
%17 = getelementptr inbounds %struct.utmpx, %struct.utmpx* %16, i32 0, i32 0
%18 = load i32, i32* %17
switch i32 %18, label %31 [
i32 130, label %19
i32 129, label %19
i32 128, label %19
i32 131, label %19
]
19: ; preds = %15, %15, %15, %15
%20 = load %struct.utmpx*, %struct.utmpx** %4
%21 = getelementptr inbounds %struct.utmpx, %struct.utmpx* %20, i32 0, i32 1
%22 = load i32, i32* %21
%23 = load %struct.utmpx*, %struct.utmpx** %3
%24 = getelementptr inbounds %struct.utmpx, %struct.utmpx* %23, i32 0, i32 1
%25 = load i32, i32* %24
%26 = call i32 @strncmp(i32 %22, i32 %25, i32 4)
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %19
%29 = load %struct.utmpx*, %struct.utmpx** %4
store %struct.utmpx* %29, %struct.utmpx** %2
br label %50
30: ; preds = %19
br label %32
31: ; preds = %15
br label %32
32: ; preds = %31, %30
br label %10
33: ; preds = %1
br label %34
34: ; preds = %49, %33
%35 = call %struct.utmpx* (...) @__getutxent()
store %struct.utmpx* %35, %struct.utmpx** %5
%36 = load %struct.utmpx*, %struct.utmpx** %5
%37 = icmp eq %struct.utmpx* %36, null
br i1 %37, label %38, label %39
38: ; preds = %34
store %struct.utmpx* null, %struct.utmpx** %2
br label %50
39: ; preds = %34
%40 = load %struct.utmpx*, %struct.utmpx** %5
%41 = getelementptr inbounds %struct.utmpx, %struct.utmpx* %40, i32 0, i32 0
%42 = load i32, i32* %41
%43 = load %struct.utmpx*, %struct.utmpx** %3
%44 = getelementptr inbounds %struct.utmpx, %struct.utmpx* %43, i32 0, i32 0
%45 = load i32, i32* %44
%46 = icmp eq i32 %42, %45
br i1 %46, label %47, label %49
47: ; preds = %39
%48 = load %struct.utmpx*, %struct.utmpx** %5
store %struct.utmpx* %48, %struct.utmpx** %2
br label %50
49: ; preds = %39
br label %34
50: ; preds = %47, %38, %28, %14
%51 = load %struct.utmpx*, %struct.utmpx** %2
ret %struct.utmpx* %51
}

LLVM IR (-O2):
%struct.utmpx = type { i32, i32 }
define %struct.utmpx* @getutxid(%struct.utmpx* nocapture %0) {
%2 = getelementptr inbounds %struct.utmpx, %struct.utmpx* %0, i64 0, i32 0
%3 = load i32, i32* %2
%4 = and i32 %3, -4
%5 = icmp eq i32 %4, 128
br i1 %5, label %6, label %26
6: ; preds = %1
%7 = tail call %struct.utmpx* (...) @__getutxent()
%8 = icmp eq %struct.utmpx* %7, null
br i1 %8, label %34, label %9
9: ; preds = %6
%10 = getelementptr inbounds %struct.utmpx, %struct.utmpx* %0, i64 0, i32 1
br label %11
11: ; preds = %9, %23
%12 = phi %struct.utmpx* [ %7, %9 ], [ %24, %23 ]
%13 = getelementptr inbounds %struct.utmpx, %struct.utmpx* %12, i64 0, i32 0
%14 = load i32, i32* %13
%15 = and i32 %14, -4
%16 = icmp eq i32 %15, 128
br i1 %16, label %17, label %23
17: ; preds = %11
%18 = getelementptr inbounds %struct.utmpx, %struct.utmpx* %12, i64 0, i32 1
%19 = load i32, i32* %18
%20 = load i32, i32* %10
%21 = tail call i32 @strncmp(i32 %19, i32 %20, i32 4)
%22 = icmp eq i32 %21, 0
br i1 %22, label %34, label %23
23: ; preds = %17, %11
%24 = tail call %struct.utmpx* (...) @__getutxent()
%25 = icmp eq %struct.utmpx* %24, null
br i1 %25, label %34, label %11
26: ; preds = %1, %29
%27 = tail call %struct.utmpx* (...) @__getutxent()
%28 = icmp eq %struct.utmpx* %27, null
br i1 %28, label %34, label %29
29: ; preds = %26
%30 = getelementptr inbounds %struct.utmpx, %struct.utmpx* %27, i64 0, i32 0
%31 = load i32, i32* %30
%32 = load i32, i32* %2
%33 = icmp eq i32 %31, %32
br i1 %33, label %34, label %26
34: ; preds = %26, %29, %23, %17, %6
%35 = phi %struct.utmpx* [ null, %6 ], [ null, %23 ], [ %12, %17 ], [ null, %26 ], [ %27, %29 ]
ret %struct.utmpx* %35
}