#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 netent {
  char *n_name;
};

/* Variables and functions */
int /*<<< orphan*/ endnetent();
struct netent *getnetent();
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ setnetent(int);
scalar_t__ strcmp(char const *, char *);
struct netent *my_getnetnam(char const *name) {
  struct netent *ptr = 0;
  setnetent(1);
  while ((ptr = getnetent()) != NULL) {
    printf("searching %s\n", ptr->n_name);
    if (strcmp(name, ptr->n_name) == 0)
      break;
  }
  endnetent();
  return (ptr);
}


x86 assembly (clang, -O0):
<my_getnetnam>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    $0x1,%edi
call   1070 <setnetent@plt>
mov    $0x0,%al
call   1040 <getnetent@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     11ba <my_getnetnam+0x6a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe6f(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11b5 <my_getnetnam+0x65>
jmp    11ba <my_getnetnam+0x6a>
jmp    116e <my_getnetnam+0x1e>
mov    $0x0,%al
call   1060 <endnetent@plt>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_getnetnam>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    $0x1,%edi
call   1070 <setnetent@plt>
lea    0xe97(%rip),%r15
nopl   0x0(%rax)
xor    %eax,%eax
call   1040 <getnetent@plt>
mov    %rax,%rbx
test   %rax,%rax
je     119a <my_getnetnam+0x4a>
mov    (%rbx),%rsi
mov    %r15,%rdi
call   1030 <printf@plt>
mov    (%rbx),%rsi
mov    %r14,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    1170 <my_getnetnam+0x20>
xor    %eax,%eax
call   1060 <endnetent@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.netent = type { i8* }
@.str = [14 x i8] c"searching %s\0A\00"
define %struct.netent* @my_getnetnam(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.netent*
store i8* %0, i8** %2
store %struct.netent* null, %struct.netent** %3
%4 = call i32 @setnetent(i32 1)
br label %5
5: ; preds = %20, %1
%6 = call %struct.netent* (...) @getnetent()
store %struct.netent* %6, %struct.netent** %3
%7 = icmp ne %struct.netent* %6, null
br i1 %7, label %8, label %21
8: ; preds = %5
%9 = load %struct.netent*, %struct.netent** %3
%10 = getelementptr inbounds %struct.netent, %struct.netent* %9, i32 0, i32 0
%11 = load i8*, i8** %10
%12 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = load i8*, i8** %2
%14 = load %struct.netent*, %struct.netent** %3
%15 = getelementptr inbounds %struct.netent, %struct.netent* %14, i32 0, i32 0
%16 = load i8*, i8** %15
%17 = call i64 @strcmp(i8* %13, i8* %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %8
br label %21
20: ; preds = %8
br label %5
21: ; preds = %19, %5
%22 = call i32 (...) @endnetent()
%23 = load %struct.netent*, %struct.netent** %3
ret %struct.netent* %23
}

LLVM IR (-O2):
%struct.netent = type { i8* }
@.str = [14 x i8] c"searching %s\0A\00"
define %struct.netent* @my_getnetnam(i8* %0) {
%2 = tail call i32 @setnetent(i32 1)
br label %3
3: ; preds = %6, %1
%4 = tail call %struct.netent* (...) @getnetent()
%5 = icmp eq %struct.netent* %4, null
br i1 %5, label %13, label %6
6: ; preds = %3
%7 = getelementptr inbounds %struct.netent, %struct.netent* %4, i64 0, i32 0
%8 = load i8*, i8** %7
%9 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = load i8*, i8** %7
%11 = tail call i64 @strcmp(i8* %0, i8* %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %3
13: ; preds = %6, %3
%14 = tail call i32 (...) @endnetent()
ret %struct.netent* %4
}