#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 sockaddr_in {
  int dummy;
};
struct hostent {
  int dummy;
};

/* Variables and functions */
char *GetCmdOpt(char *, int, char **);
int /*<<< orphan*/ error(int);
int /*<<< orphan*/ exit(int);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  struct hostent *hp;
  struct sockaddr_in sadd;
  int ssock;
  unsigned char sip[4];
  struct sockaddr_in cadd;
  int csock;
  int l;
  int magic;
  char *sname;
  char *portname;
  int port;
  sname = GetCmdOpt("-s", argc, argv);
  if (!sname) {
    printf("missing opt -s ( servername )\n");
    exit(-1);
  }
  hp = gethostbyname(sname);
  if (!hp) {
    printf("gethostbyname: failed ( name: %s )\n", sname);
    error(-1);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%rdx
lea    0xe8c(%rip),%rdi
call   1030 <GetCmdOpt@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    11a0 <main+0x50>
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    -0x48(%rbp),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d4 <main+0x84>
mov    -0x48(%rbp),%rsi
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1060 <error@plt>
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    %rsi,%rdx
mov    %edi,%esi
lea    0xe93(%rip),%rdi
call   1030 <GetCmdOpt@plt>
test   %rax,%rax
je     11a6 <main+0x46>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <gethostbyname@plt>
test   %rax,%rax
jne    11a2 <main+0x42>
lea    0xe75(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <error@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe7a(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.hostent = type { i32 }
%struct.sockaddr_in = type { i32 }
@.str = [3 x i8] c"-s\00"
@.str.1 = [31 x i8] c"missing opt -s ( servername )\0A\00"
@.str.2 = [36 x i8] c"gethostbyname: failed ( name: %s )\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.hostent*
%7 = alloca %struct.sockaddr_in
%8 = alloca i32
%9 = alloca [4 x i8]
%10 = alloca %struct.sockaddr_in
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = load i32, i32* %4
%18 = load i8**, i8*** %5
%19 = call i8* @GetCmdOpt(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %17, i8** %18)
store i8* %19, i8** %14
%20 = load i8*, i8** %14
%21 = icmp ne i8* %20, null
br i1 %21, label %25, label %22
22: ; preds = %2
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @exit(i32 -1)
unreachable
25: ; preds = %2
%26 = load i8*, i8** %14
%27 = call %struct.hostent* @gethostbyname(i8* %26)
store %struct.hostent* %27, %struct.hostent** %6
%28 = load %struct.hostent*, %struct.hostent** %6
%29 = icmp ne %struct.hostent* %28, null
br i1 %29, label %34, label %30
30: ; preds = %25
%31 = load i8*, i8** %14
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %31)
%33 = call i32 @error(i32 -1)
br label %34
34: ; preds = %30, %25
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
%struct.hostent = type { i32 }
@.str = [3 x i8] c"-s\00"
@.str.2 = [36 x i8] c"gethostbyname: failed ( name: %s )\0A\00"
@str = [30 x i8] c"missing opt -s ( servername )\00"
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i8* @GetCmdOpt(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %0, i8** %1)
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 -1)
unreachable
8: ; preds = %2
%9 = tail call %struct.hostent* @gethostbyname(i8* %3)
%10 = icmp eq %struct.hostent* %9, null
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%13 = tail call i32 @error(i32 -1)
br label %14
14: ; preds = %11, %8
ret i32 0
}