#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 in_addr {
  int dummy;
};
struct hostent {
  char *h_name;
  int /*<<< orphan*/ **h_addr_list;
};

/* Variables and functions */
int /*<<< orphan*/ atoi(char *);
struct hostent *gethostbyname(char *);
char *inet_ntoa(struct in_addr);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ send_message(struct in_addr, int, char *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  struct hostent *h;
  unsigned int i;
  int port = 7010;
  if (argc != 4) {
    printf("usage: histd_client addr metric_name metric_value\n");
    return 1;
  }
  h = gethostbyname(argv[1]);
  if (h == NULL) {
    printf("gethostbyname() failed\n");
  } else {
    printf("sending to %s\n", h->h_name);
    for (i = 0; h->h_addr_list[i] != NULL; i++) {
      printf("trying %s\n", inet_ntoa(*(struct in_addr *)(h->h_addr_list[i])));
      if (send_message(*(struct in_addr *)(h->h_addr_list[i]), port, argv[2],
                       atoi(argv[3])) == 0) {
        printf("ok\n");
        break;
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1b62,-0x20(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     1191 <main+0x41>
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    129b <main+0x14b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <gethostbyname@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c0 <main+0x70>
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1294 <main+0x144>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x1c(%rbp),%ecx
cmpq   $0x0,(%rax,%rcx,8)
je     128f <main+0x13f>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x1c(%rbp),%ecx
mov    (%rax,%rcx,8),%rax
mov    (%rax),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,%rsi
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x1c(%rbp),%ecx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1070 <atoi@plt>
mov    -0x34(%rbp),%esi
mov    -0x30(%rbp),%rdx
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    (%rax),%edi
call   1050 <send_message@plt>
cmp    $0x0,%rax
jne    127c <main+0x12c>
lea    0xdf5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    128f <main+0x13f>
jmp    1281 <main+0x131>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11dc <main+0x8c>
jmp    1294 <main+0x144>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x4,%edi
jne    1215 <main+0xb5>
mov    %rsi,%r15
mov    0x8(%rsi),%rdi
call   1070 <gethostbyname@plt>
test   %rax,%rax
je     1223 <main+0xc3>
mov    %rax,%rbx
mov    (%rax),%rsi
lea    0xe6a(%rip),%rdi
xor    %ebp,%ebp
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rbx),%rax
mov    (%rax),%rax
test   %rax,%rax
je     123c <main+0xdc>
lea    0xe59(%rip),%r13
xor    %r12d,%r12d
nopl   0x0(%rax)
mov    (%rax),%edi
call   1040 <inet_ntoa@plt>
mov    %r13,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rbx),%rax
mov    (%rax,%r12,8),%r14
mov    0x10(%r15),%rbp
mov    0x18(%r15),%rdi
call   1080 <atoi@plt>
mov    (%r14),%edi
mov    $0x1b62,%esi
mov    %rbp,%rdx
mov    %eax,%ecx
call   1060 <send_message@plt>
test   %rax,%rax
je     122e <main+0xce>
add    $0x1,%r12d
mov    0x8(%rbx),%rax
mov    (%rax,%r12,8),%rax
test   %rax,%rax
jne    11c0 <main+0x60>
xor    %ebp,%ebp
jmp    123c <main+0xdc>
mov    $0x1,%ebp
lea    0xe13(%rip),%rdi
jmp    1237 <main+0xd7>
xor    %ebp,%ebp
lea    0xdf1(%rip),%rdi
jmp    1237 <main+0xd7>
xor    %ebp,%ebp
lea    0xde3(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.hostent = type { i8*, i32** }
%struct.in_addr = type { i32 }
@.str = [51 x i8] c"usage: histd_client addr metric_name metric_value\0A\00"
@.str.1 = [24 x i8] c"gethostbyname() failed\0A\00"
@.str.2 = [15 x i8] c"sending to %s\0A\00"
@.str.3 = [11 x i8] c"trying %s\0A\00"
@.str.4 = [4 x i8] c"ok\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.hostent*
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 7010, i32* %8
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 4
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %77
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call %struct.hostent* @gethostbyname(i8* %16)
store %struct.hostent* %17, %struct.hostent** %6
%18 = load %struct.hostent*, %struct.hostent** %6
%19 = icmp eq %struct.hostent* %18, null
br i1 %19, label %20, label %22
20: ; preds = %13
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %76
22: ; preds = %13
%23 = load %struct.hostent*, %struct.hostent** %6
%24 = getelementptr inbounds %struct.hostent, %struct.hostent* %23, i32 0, i32 0
%25 = load i8*, i8** %24
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %25)
store i32 0, i32* %7
br label %27
27: ; preds = %72, %22
%28 = load %struct.hostent*, %struct.hostent** %6
%29 = getelementptr inbounds %struct.hostent, %struct.hostent* %28, i32 0, i32 1
%30 = load i32**, i32*** %29
%31 = load i32, i32* %7
%32 = zext i32 %31 to i64
%33 = getelementptr inbounds i32*, i32** %30, i64 %32
%34 = load i32*, i32** %33
%35 = icmp ne i32* %34, null
br i1 %35, label %36, label %75
36: ; preds = %27
%37 = load %struct.hostent*, %struct.hostent** %6
%38 = getelementptr inbounds %struct.hostent, %struct.hostent* %37, i32 0, i32 1
%39 = load i32**, i32*** %38
%40 = load i32, i32* %7
%41 = zext i32 %40 to i64
%42 = getelementptr inbounds i32*, i32** %39, i64 %41
%43 = load i32*, i32** %42
%44 = bitcast i32* %43 to %struct.in_addr*
%45 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %44, i32 0, i32 0
%46 = load i32, i32* %45
%47 = call i8* @inet_ntoa(i32 %46)
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %47)
%49 = load %struct.hostent*, %struct.hostent** %6
%50 = getelementptr inbounds %struct.hostent, %struct.hostent* %49, i32 0, i32 1
%51 = load i32**, i32*** %50
%52 = load i32, i32* %7
%53 = zext i32 %52 to i64
%54 = getelementptr inbounds i32*, i32** %51, i64 %53
%55 = load i32*, i32** %54
%56 = bitcast i32* %55 to %struct.in_addr*
%57 = load i32, i32* %8
%58 = load i8**, i8*** %5
%59 = getelementptr inbounds i8*, i8** %58, i64 2
%60 = load i8*, i8** %59
%61 = load i8**, i8*** %5
%62 = getelementptr inbounds i8*, i8** %61, i64 3
%63 = load i8*, i8** %62
%64 = call i32 @atoi(i8* %63)
%65 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %56, i32 0, i32 0
%66 = load i32, i32* %65
%67 = call i64 @send_message(i32 %66, i32 %57, i8* %60, i32 %64)
%68 = icmp eq i64 %67, 0
br i1 %68, label %69, label %71
69: ; preds = %36
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
br label %75
71: ; preds = %36
br label %72
72: ; preds = %71
%73 = load i32, i32* %7
%74 = add i32 %73, 1
store i32 %74, i32* %7
br label %27
75: ; preds = %69, %27
br label %76
76: ; preds = %75, %20
store i32 0, i32* %3
br label %77
77: ; preds = %76, %11
%78 = load i32, i32* %3
ret i32 %78
}

LLVM IR (-O2):
%struct.hostent = type { i8*, i32** }
%struct.in_addr = type { i32 }
@.str.2 = [15 x i8] c"sending to %s\0A\00"
@.str.3 = [11 x i8] c"trying %s\0A\00"
@str = [3 x i8] c"ok\00"
@str.5 = [23 x i8] c"gethostbyname() failed\00"
@str.6 = [50 x i8] c"usage: histd_client addr metric_name metric_value\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 4
br i1 %3, label %4, label %44
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call %struct.hostent* @gethostbyname(i8* %6)
%8 = icmp eq %struct.hostent* %7, null
br i1 %8, label %44, label %9
9: ; preds = %4
%10 = getelementptr inbounds %struct.hostent, %struct.hostent* %7, i64 0, i32 0
%11 = load i8*, i8** %10
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %11)
%13 = getelementptr inbounds %struct.hostent, %struct.hostent* %7, i64 0, i32 1
%14 = load i32**, i32*** %13
%15 = load i32*, i32** %14
%16 = icmp eq i32* %15, null
br i1 %16, label %48, label %17
17: ; preds = %9
%18 = getelementptr inbounds i8*, i8** %1, i64 2
%19 = getelementptr inbounds i8*, i8** %1, i64 3
br label %27
20: ; preds = %27
%21 = add nuw nsw i64 %29, 1
%22 = load i32**, i32*** %13
%23 = and i64 %21, 4294967295
%24 = getelementptr inbounds i32*, i32** %22, i64 %23
%25 = load i32*, i32** %24
%26 = icmp eq i32* %25, null
br i1 %26, label %48, label %27
27: ; preds = %17, %20
%28 = phi i32* [ %15, %17 ], [ %25, %20 ]
%29 = phi i64 [ 0, %17 ], [ %23, %20 ]
%30 = load i32, i32* %28
%31 = tail call i8* @inet_ntoa(i32 %30)
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %31)
%33 = load i32**, i32*** %13
%34 = getelementptr inbounds i32*, i32** %33, i64 %29
%35 = bitcast i32** %34 to %struct.in_addr**
%36 = load %struct.in_addr*, %struct.in_addr** %35
%37 = load i8*, i8** %18
%38 = load i8*, i8** %19
%39 = tail call i32 @atoi(i8* %38)
%40 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %36, i64 0, i32 0
%41 = load i32, i32* %40
%42 = tail call i64 @send_message(i32 %41, i32 7010, i8* %37, i32 %39)
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %20
44: ; preds = %27, %4, %2
%45 = phi i8* [ getelementptr inbounds ([50 x i8], [50 x i8]* @str.6, i64 0, i64 0), %2 ], [ getelementptr inbounds ([23 x i8], [23 x i8]* @str.5, i64 0, i64 0), %4 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0), %27 ]
%46 = phi i32 [ 1, %2 ], [ 0, %4 ], [ 0, %27 ]
%47 = tail call i32 @puts(i8* dereferenceable(1) %45)
br label %48
48: ; preds = %20, %44, %9
%49 = phi i32 [ 0, %9 ], [ %46, %44 ], [ 0, %20 ]
ret i32 %49
}