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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
struct passwd *getpwent();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ setpwent();
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ *strchr(int /*<<< orphan*/, char);
int main(int argc, char **argv) {
  struct passwd *pw;
  int i;
  while (1) {
    setpwent();
    while ((pw = getpwent()) != NULL) {
      if (strchr(pw->pw_name, '/') != NULL) {
        break;
      }
    }
    if (pw != NULL) {
      i++;
      printf("got pwent handle %d\n", i);
    } else {
      printf("winbind daemon not running?\n");
      exit(1);
    }
    sleep(1);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1050 <setpwent@plt>
mov    $0x0,%al
call   1060 <getpwent@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11b6 <main+0x56>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
mov    $0x2f,%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
je     11b1 <main+0x51>
jmp    11b6 <main+0x56>
jmp    117d <main+0x1d>
cmpq   $0x0,-0x18(%rbp)
je     11e0 <main+0x80>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11f8 <main+0x98>
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    $0x1,%edi
call   1080 <sleep@plt>
jmp    1176 <main+0x16>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
lea    0xe86(%rip),%rbx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <setpwent@plt>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1070 <getpwent@plt>
test   %rax,%rax
je     11c8 <main+0x58>
mov    (%rax),%edi
mov    $0x2f,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1190 <main+0x20>
add    $0x1,%ebp
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
jmp    1180 <main+0x10>
lea    0xe46(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.passwd = type { i32 }
@.str = [21 x i8] c"got pwent handle %d\0A\00"
@.str.1 = [29 x i8] c"winbind daemon not running?\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.passwd*
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %8
8: ; preds = %2, %32
%9 = call i32 (...) @setpwent()
br label %10
10: ; preds = %20, %8
%11 = call %struct.passwd* (...) @getpwent()
store %struct.passwd* %11, %struct.passwd** %6
%12 = icmp ne %struct.passwd* %11, null
br i1 %12, label %13, label %21
13: ; preds = %10
%14 = load %struct.passwd*, %struct.passwd** %6
%15 = getelementptr inbounds %struct.passwd, %struct.passwd* %14, i32 0, i32 0
%16 = load i32, i32* %15
%17 = call i32* @strchr(i32 %16, i8 signext 47)
%18 = icmp ne i32* %17, null
br i1 %18, label %19, label %20
19: ; preds = %13
br label %21
20: ; preds = %13
br label %10
21: ; preds = %19, %10
%22 = load %struct.passwd*, %struct.passwd** %6
%23 = icmp ne %struct.passwd* %22, null
br i1 %23, label %24, label %29
24: ; preds = %21
%25 = load i32, i32* %7
%26 = add nsw i32 %25, 1
store i32 %26, i32* %7
%27 = load i32, i32* %7
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %27)
br label %32
29: ; preds = %21
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %24
%33 = call i32 @sleep(i32 1)
br label %8
}

LLVM IR (-O2):
%struct.passwd = type { i32 }
@.str = [21 x i8] c"got pwent handle %d\0A\00"
@str = [28 x i8] c"winbind daemon not running?\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
br label %3
3: ; preds = %14, %2
%4 = phi i32 [ undef, %2 ], [ %15, %14 ]
%5 = tail call i32 (...) @setpwent()
br label %6
6: ; preds = %9, %3
%7 = tail call %struct.passwd* (...) @getpwent()
%8 = icmp eq %struct.passwd* %7, null
br i1 %8, label %18, label %9
9: ; preds = %6
%10 = getelementptr inbounds %struct.passwd, %struct.passwd* %7, i64 0, i32 0
%11 = load i32, i32* %10
%12 = tail call i32* @strchr(i32 %11, i8 signext 47)
%13 = icmp eq i32* %12, null
br i1 %13, label %6, label %14
14: ; preds = %9
%15 = add nsw i32 %4, 1
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = tail call i32 @sleep(i32 1)
br label %3
18: ; preds = %6
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
%20 = tail call i32 @exit(i32 1)
unreachable
}