#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;
};

/* Variables and functions */
struct utmpx *getutxent();
int /*<<< orphan*/ setutxent();
int myuptime_count_connected_users() {
  struct utmpx *user_info;
  int nbr_user;
  setutxent();
  nbr_user = 0;
  while ((user_info = getutxent()) != NULL) {
    if (user_info->ut_type == 7)
      nbr_user++;
  }
  return nbr_user;
}


x86 assembly (clang, -O0):
<myuptime_count_connected_users>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1030 <setutxent@plt>
movl   $0x0,-0xc(%rbp)
mov    $0x0,%al
call   1040 <getutxent@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
je     1166 <myuptime_count_connected_users+0x46>
mov    -0x8(%rbp),%rax
cmpl   $0x7,(%rax)
jne    1161 <myuptime_count_connected_users+0x41>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1136 <myuptime_count_connected_users+0x16>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<myuptime_count_connected_users>:
push   %rbx
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <setutxent@plt>
xor    %eax,%eax
call   1040 <getutxent@plt>
test   %rax,%rax
je     1156 <myuptime_count_connected_users+0x36>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
xor    %ecx,%ecx
cmpl   $0x7,(%rax)
sete   %cl
add    %ecx,%ebx
xor    %eax,%eax
call   1040 <getutxent@plt>
test   %rax,%rax
jne    1140 <myuptime_count_connected_users+0x20>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.utmpx = type { i32 }
define i32 @myuptime_count_connected_users() {
%1 = alloca %struct.utmpx*
%2 = alloca i32
%3 = call i32 (...) @setutxent()
store i32 0, i32* %2
br label %4
4: ; preds = %15, %0
%5 = call %struct.utmpx* (...) @getutxent()
store %struct.utmpx* %5, %struct.utmpx** %1
%6 = icmp ne %struct.utmpx* %5, null
br i1 %6, label %7, label %16
7: ; preds = %4
%8 = load %struct.utmpx*, %struct.utmpx** %1
%9 = getelementptr inbounds %struct.utmpx, %struct.utmpx* %8, i32 0, i32 0
%10 = load i32, i32* %9
%11 = icmp eq i32 %10, 7
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = load i32, i32* %2
%14 = add nsw i32 %13, 1
store i32 %14, i32* %2
br label %15
15: ; preds = %12, %7
br label %4
16: ; preds = %4
%17 = load i32, i32* %2
ret i32 %17
}

LLVM IR (-O2):
%struct.utmpx = type { i32 }
define i32 @myuptime_count_connected_users() {
%1 = tail call i32 (...) @setutxent()
%2 = tail call %struct.utmpx* (...) @getutxent()
%3 = icmp eq %struct.utmpx* %2, null
br i1 %3, label %14, label %4
4: ; preds = %0, %4
%5 = phi %struct.utmpx* [ %12, %4 ], [ %2, %0 ]
%6 = phi i32 [ %11, %4 ], [ 0, %0 ]
%7 = getelementptr inbounds %struct.utmpx, %struct.utmpx* %5, i64 0, i32 0
%8 = load i32, i32* %7
%9 = icmp eq i32 %8, 7
%10 = zext i1 %9 to i32
%11 = add nuw nsw i32 %6, %10
%12 = tail call %struct.utmpx* (...) @getutxent()
%13 = icmp eq %struct.utmpx* %12, null
br i1 %13, label %14, label %4
14: ; preds = %4, %0
%15 = phi i32 [ 0, %0 ], [ %11, %4 ]
ret i32 %15
}