#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 servent {
  int /*<<< orphan*/ s_proto;
  int /*<<< orphan*/ s_port;
  int /*<<< orphan*/ s_aliases;
  int /*<<< orphan*/ s_name;
};

/* Variables and functions */
int /*<<< orphan*/ htons(int /*<<< orphan*/);
struct servent *setreturned(struct servent *p) {
  static struct servent returned;
  returned.s_name = p->s_name;
  returned.s_aliases = p->s_aliases;
  returned.s_port = htons(p->s_port);
  returned.s_proto = p->s_proto;
  return &returned;
}


x86 assembly (clang, -O0):
<setreturned>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    0xc(%rax),%eax
mov    %eax,0x2f0f(%rip)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%eax
mov    %eax,0x2efe(%rip)
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%edi
call   1030 <htons@plt>
mov    %eax,0x2ee8(%rip)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,0x2ed8(%rip)
lea    0x2ed1(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setreturned>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0xc(%rdi),%eax
mov    %eax,0x2f18(%rip)
lea    0x2f05(%rip),%r14
mov    0x8(%rdi),%eax
mov    %eax,0x2f04(%rip)
mov    0x4(%rdi),%edi
call   1030 <htons@plt>
mov    %eax,0x2ef2(%rip)
mov    (%rbx),%eax
mov    %eax,0x2ee6(%rip)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.servent = type { i32, i32, i32, i32 }
@setreturned.returned = internal global %struct.servent zeroinitializer
define %struct.servent* @setreturned(%struct.servent* %0) {
%2 = alloca %struct.servent*
store %struct.servent* %0, %struct.servent** %2
%3 = load %struct.servent*, %struct.servent** %2
%4 = getelementptr inbounds %struct.servent, %struct.servent* %3, i32 0, i32 3
%5 = load i32, i32* %4
store i32 %5, i32* getelementptr inbounds (%struct.servent, %struct.servent* @setreturned.returned, i32 0, i32 3)
%6 = load %struct.servent*, %struct.servent** %2
%7 = getelementptr inbounds %struct.servent, %struct.servent* %6, i32 0, i32 2
%8 = load i32, i32* %7
store i32 %8, i32* getelementptr inbounds (%struct.servent, %struct.servent* @setreturned.returned, i32 0, i32 2)
%9 = load %struct.servent*, %struct.servent** %2
%10 = getelementptr inbounds %struct.servent, %struct.servent* %9, i32 0, i32 1
%11 = load i32, i32* %10
%12 = call i32 @htons(i32 %11)
store i32 %12, i32* getelementptr inbounds (%struct.servent, %struct.servent* @setreturned.returned, i32 0, i32 1)
%13 = load %struct.servent*, %struct.servent** %2
%14 = getelementptr inbounds %struct.servent, %struct.servent* %13, i32 0, i32 0
%15 = load i32, i32* %14
store i32 %15, i32* getelementptr inbounds (%struct.servent, %struct.servent* @setreturned.returned, i32 0, i32 0)
ret %struct.servent* @setreturned.returned
}

LLVM IR (-O2):
%struct.servent = type { i32, i32, i32, i32 }
@setreturned.returned = internal global %struct.servent zeroinitializer
define %struct.servent* @setreturned(%struct.servent* nocapture %0) {
%2 = getelementptr inbounds %struct.servent, %struct.servent* %0, i64 0, i32 3
%3 = load i32, i32* %2
store i32 %3, i32* getelementptr inbounds (%struct.servent, %struct.servent* @setreturned.returned, i64 0, i32 3)
%4 = getelementptr inbounds %struct.servent, %struct.servent* %0, i64 0, i32 2
%5 = load i32, i32* %4
store i32 %5, i32* getelementptr inbounds (%struct.servent, %struct.servent* @setreturned.returned, i64 0, i32 2)
%6 = getelementptr inbounds %struct.servent, %struct.servent* %0, i64 0, i32 1
%7 = load i32, i32* %6
%8 = tail call i32 @htons(i32 %7)
store i32 %8, i32* getelementptr inbounds (%struct.servent, %struct.servent* @setreturned.returned, i64 0, i32 1)
%9 = getelementptr inbounds %struct.servent, %struct.servent* %0, i64 0, i32 0
%10 = load i32, i32* %9
store i32 %10, i32* getelementptr inbounds (%struct.servent, %struct.servent* @setreturned.returned, i64 0, i32 0)
ret %struct.servent* @setreturned.returned
}