#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
void definirEstructura(unsigned int flag, char *ip, int puerto,
                       struct sockaddr_in *e) {
  bzero((char *)e, sizeof(*e));
  e->sin_family = AF_INET;
  e->sin_addr.s_addr = (flag == 0 || ip == NULL) ? INADDR_ANY : inet_addr(ip);
  e->sin_port = htons(puerto);
}


x86 assembly (clang, -O0):
<definirEstructura>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0xc,%esi
call   1050 <bzero@plt>
mov    0x2e8d(%rip),%rax
mov    (%rax),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,0x8(%rax)
cmpl   $0x0,-0x4(%rbp)
je     1179 <definirEstructura+0x49>
cmpq   $0x0,-0x10(%rbp)
jne    118a <definirEstructura+0x5a>
mov    0x2e60(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
jmp    1196 <definirEstructura+0x66>
mov    -0x10(%rbp),%rdi
call   1040 <inet_addr@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x14(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<definirEstructura>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%rbx
mov    %edx,%r14d
mov    %rsi,%r15
mov    %edi,%ebp
mov    %rcx,%rdi
mov    $0xc,%esi
call   1050 <bzero@plt>
mov    0x2e92(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rbx)
test   %ebp,%ebp
je     116e <definirEstructura+0x3e>
test   %r15,%r15
je     116e <definirEstructura+0x3e>
mov    %r15,%rdi
call   1040 <inet_addr@plt>
jmp    1177 <definirEstructura+0x47>
mov    0x2e6b(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rbx)
mov    %r14d,%edi
call   1030 <htons@plt>
mov    %eax,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
define void @definirEstructura(i32 %0, i8* %1, i32 %2, %struct.sockaddr_in* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca %struct.sockaddr_in*
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store %struct.sockaddr_in* %3, %struct.sockaddr_in** %8
%9 = load %struct.sockaddr_in*, %struct.sockaddr_in** %8
%10 = bitcast %struct.sockaddr_in* %9 to i8*
%11 = call i32 @bzero(i8* %10, i32 12)
%12 = load i32, i32* @AF_INET
%13 = load %struct.sockaddr_in*, %struct.sockaddr_in** %8
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 2
store i32 %12, i32* %14
%15 = load i32, i32* %5
%16 = icmp eq i32 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %4
%18 = load i8*, i8** %6
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %22
20: ; preds = %17, %4
%21 = load i32, i32* @INADDR_ANY
br label %25
22: ; preds = %17
%23 = load i8*, i8** %6
%24 = call i32 @inet_addr(i8* %23)
br label %25
25: ; preds = %22, %20
%26 = phi i32 [ %21, %20 ], [ %24, %22 ]
%27 = load %struct.sockaddr_in*, %struct.sockaddr_in** %8
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %27, i32 0, i32 1
%29 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %28, i32 0, i32 0
store i32 %26, i32* %29
%30 = load i32, i32* %7
%31 = call i32 @htons(i32 %30)
%32 = load %struct.sockaddr_in*, %struct.sockaddr_in** %8
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %32, i32 0, i32 0
store i32 %31, i32* %33
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
define void @definirEstructura(i32 %0, i8* %1, i32 %2, %struct.sockaddr_in* nocapture writeonly %3) {
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = tail call i32 @bzero(i8* %5, i32 12)
%7 = load i32, i32* @AF_INET
%8 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %7, i32* %8
%9 = icmp eq i32 %0, 0
%10 = icmp eq i8* %1, null
%11 = or i1 %9, %10
br i1 %11, label %12, label %14
12: ; preds = %4
%13 = load i32, i32* @INADDR_ANY
br label %16
14: ; preds = %4
%15 = tail call i32 @inet_addr(i8* %1)
br label %16
16: ; preds = %14, %12
%17 = phi i32 [ %13, %12 ], [ %15, %14 ]
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %17, i32* %18
%19 = tail call i32 @htons(i32 %2)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %19, i32* %20
ret void
}