#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;
  int n_addrtype;
  int /*<<< orphan*/ n_net;
};
struct in_addr {
  int /*<<< orphan*/ s_addr;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
char *inet_ntoa(struct in_addr);
struct netent *my_getnetnam(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, int, char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  struct netent *result;
  if (argc != 2) {
    fprintf(stderr, "Usage: %s hostname\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  result = my_getnetnam(argv[1]);
  if (result == NULL) {
    perror("getnetnam");
    exit(EXIT_FAILURE);
  }
  struct in_addr addr;
  addr.s_addr = result->n_net;
  printf("Name: %s; type: %d; addr: %s\n", result->n_name, result->n_addrtype,
         inet_ntoa(addr));
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11aa <main+0x4a>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe69(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <my_getnetnam@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e0 <main+0x80>
lea    0xe47(%rip),%rdi
call   1070 <perror@plt>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%rax
mov    0xc(%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    -0x30(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    %rax,%rcx
lea    0xe06(%rip),%rdi
call   1050 <printf@plt>
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    1184 <main+0x24>
mov    0x8(%rsi),%rdi
call   1030 <my_getnetnam@plt>
test   %rax,%rax
jne    11aa <main+0x4a>
lea    0xe97(%rip),%rdi
call   1070 <perror@plt>
jmp    119c <main+0x3c>
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xe69(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    0xc(%rax),%edi
mov    (%rax),%rbx
mov    0x8(%rax),%ebp
call   1040 <inet_ntoa@plt>
lea    0xe5f(%rip),%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
mov    %rax,%rcx
call   1050 <printf@plt>
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.netent = type { i8*, i32, i32 }
%struct.in_addr = type { i32 }
@stderr = global i32 0
@.str = [20 x i8] c"Usage: %s hostname\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [10 x i8] c"getnetnam\00"
@.str.2 = [30 x i8] c"Name: %s; type: %d; addr: %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.netent*
%7 = alloca %struct.in_addr
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %18
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call %struct.netent* @my_getnetnam(i8* %21)
store %struct.netent* %22, %struct.netent** %6
%23 = load %struct.netent*, %struct.netent** %6
%24 = icmp eq %struct.netent* %23, null
br i1 %24, label %25, label %29
25: ; preds = %18
%26 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %18
%30 = load %struct.netent*, %struct.netent** %6
%31 = getelementptr inbounds %struct.netent, %struct.netent* %30, i32 0, i32 2
%32 = load i32, i32* %31
%33 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %7, i32 0, i32 0
store i32 %32, i32* %33
%34 = load %struct.netent*, %struct.netent** %6
%35 = getelementptr inbounds %struct.netent, %struct.netent* %34, i32 0, i32 0
%36 = load i8*, i8** %35
%37 = load %struct.netent*, %struct.netent** %6
%38 = getelementptr inbounds %struct.netent, %struct.netent* %37, i32 0, i32 1
%39 = load i32, i32* %38
%40 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %7, i32 0, i32 0
%41 = load i32, i32* %40
%42 = call i8* @inet_ntoa(i32 %41)
%43 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %36, i32 %39, i8* %42)
%44 = load i32, i32* @EXIT_SUCCESS
%45 = call i32 @exit(i32 %44)
unreachable
}

LLVM IR (-O2):
%struct.netent = type { i8*, i32, i32 }
@stderr = global i32 0
@.str = [20 x i8] c"Usage: %s hostname\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [10 x i8] c"getnetnam\00"
@.str.2 = [30 x i8] c"Name: %s; type: %d; addr: %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %10, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call %struct.netent* @my_getnetnam(i8* %12)
%14 = icmp eq %struct.netent* %13, null
br i1 %14, label %15, label %19
15: ; preds = %10
%16 = tail call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = tail call i32 @exit(i32 %17)
unreachable
19: ; preds = %10
%20 = getelementptr inbounds %struct.netent, %struct.netent* %13, i64 0, i32 2
%21 = load i32, i32* %20
%22 = getelementptr inbounds %struct.netent, %struct.netent* %13, i64 0, i32 0
%23 = load i8*, i8** %22
%24 = getelementptr inbounds %struct.netent, %struct.netent* %13, i64 0, i32 1
%25 = load i32, i32* %24
%26 = tail call i8* @inet_ntoa(i32 %21)
%27 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %23, i32 %25, i8* %26)
%28 = load i32, i32* @EXIT_SUCCESS
%29 = tail call i32 @exit(i32 %28)
unreachable
}