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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  struct timeval begin, end;
  int cnt = 0;
  struct hostent *h;
  if (argc != 2) {
    fprintf(stderr, "Usage: %s <hostname>\n", argv[0]);
    exit(1);
  }
  gettimeofday(&begin, NULL);
  {
    int i;
    for (i = 0; i < 10000; ++i) {
      h = gethostbyname(argv[1]);
      if (!h) {
        perror("gethostbyname failed!");
      }
      cnt++;
    }
  }
  gettimeofday(&end, NULL);
  printf("Total count: %d\n", cnt);
  printf("Total time: %lg s\n",
         (end.tv_sec - begin.tv_sec) + 1e-6 * (end.tv_usec - begin.tv_usec));
}


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   $0x0,-0x24(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11ad <main+0x4d>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe6a(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
movl   $0x0,-0x34(%rbp)
cmpl   $0x2710,-0x34(%rbp)
jge    120d <main+0xad>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11f6 <main+0x96>
lea    0xe2d(%rip),%rdi
call   1070 <perror@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11c1 <main+0x61>
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    -0x24(%rbp),%esi
lea    0xe10(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
sub    -0x18(%rbp),%eax
cvtsi2sd %eax,%xmm1
mov    -0x1c(%rbp),%eax
sub    -0x14(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  0xdbb(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%esi
lea    0xded(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    1206 <main+0xa6>
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    $0x2710,%ebp
lea    0xe92(%rip),%r14
jmp    1195 <main+0x35>
xchg   %ax,%ax
add    $0xffffffff,%ebp
je     11ad <main+0x4d>
mov    0x8(%rbx),%rdi
call   1050 <gethostbyname@plt>
test   %rax,%rax
jne    1190 <main+0x30>
mov    %r14,%rdi
call   1070 <perror@plt>
jmp    1190 <main+0x30>
mov    %rsp,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
lea    0xe76(%rip),%rdi
mov    $0x2710,%esi
call   1030 <printf@plt>
mov    (%rsp),%eax
mov    0x4(%rsp),%ecx
sub    0x8(%rsp),%eax
cvtsi2sd %eax,%xmm0
sub    0xc(%rsp),%ecx
cvtsi2sd %ecx,%xmm1
mulsd  0xe19(%rip),%xmm1
addsd  %xmm0,%xmm1
cvttsd2si %xmm1,%esi
lea    0xe4f(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xdef(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
%struct.hostent = type { i32 }
@stderr = global i32 0
@.str = [22 x i8] c"Usage: %s <hostname>\0A\00"
@.str.1 = [22 x i8] c"gethostbyname failed!\00"
@.str.2 = [17 x i8] c"Total count: %d\0A\00"
@.str.3 = [19 x i8] c"Total time: %lg s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.timeval
%7 = alloca %struct.timeval
%8 = alloca i32
%9 = alloca %struct.hostent*
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 2
br i1 %12, label %13, label %20
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
store i32 0, i32* %10
br label %22
22: ; preds = %37, %20
%23 = load i32, i32* %10
%24 = icmp slt i32 %23, 10000
br i1 %24, label %25, label %40
25: ; preds = %22
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call %struct.hostent* @gethostbyname(i8* %28)
store %struct.hostent* %29, %struct.hostent** %9
%30 = load %struct.hostent*, %struct.hostent** %9
%31 = icmp ne %struct.hostent* %30, null
br i1 %31, label %34, label %32
32: ; preds = %25
%33 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %34
34: ; preds = %32, %25
%35 = load i32, i32* %8
%36 = add nsw i32 %35, 1
store i32 %36, i32* %8
br label %37
37: ; preds = %34
%38 = load i32, i32* %10
%39 = add nsw i32 %38, 1
store i32 %39, i32* %10
br label %22
40: ; preds = %22
%41 = call i32 @gettimeofday(%struct.timeval* %7, i32* null)
%42 = load i32, i32* %8
%43 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %42)
%44 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
%45 = load i32, i32* %44
%46 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%47 = load i32, i32* %46
%48 = sub nsw i32 %45, %47
%49 = sitofp i32 %48 to double
%50 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 1
%51 = load i32, i32* %50
%52 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 1
%53 = load i32, i32* %52
%54 = sub nsw i32 %51, %53
%55 = sitofp i32 %54 to double
%56 = call double @llvm.fmuladd.f64(double 0x3EB0C6F7A0B5ED8D, double %55, double %49)
%57 = fptosi double %56 to i32
%58 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %57)
%59 = load i32, i32* %3
ret i32 %59
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
%struct.hostent = type { i32 }
@stderr = global i32 0
@.str = [22 x i8] c"Usage: %s <hostname>\0A\00"
@.str.1 = [22 x i8] c"gethostbyname failed!\00"
@.str.2 = [17 x i8] c"Total count: %d\0A\00"
@.str.3 = [19 x i8] c"Total time: %lg s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = bitcast %struct.timeval* %3 to i8*
%6 = bitcast %struct.timeval* %4 to i8*
%7 = icmp eq i32 %0, 2
br i1 %7, label %13, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%15 = getelementptr inbounds i8*, i8** %1, i64 1
br label %16
16: ; preds = %13, %23
%17 = phi i32 [ 0, %13 ], [ %24, %23 ]
%18 = load i8*, i8** %15
%19 = tail call %struct.hostent* @gethostbyname(i8* %18)
%20 = icmp eq %struct.hostent* %19, null
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %21, %16
%24 = add nuw nsw i32 %17, 1
%25 = icmp eq i32 %24, 10000
br i1 %25, label %26, label %16
26: ; preds = %23
%27 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%28 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 10000)
%29 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%30 = load i32, i32* %29
%31 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%32 = load i32, i32* %31
%33 = sub nsw i32 %30, %32
%34 = sitofp i32 %33 to double
%35 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%36 = load i32, i32* %35
%37 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%38 = load i32, i32* %37
%39 = sub nsw i32 %36, %38
%40 = sitofp i32 %39 to double
%41 = tail call double @llvm.fmuladd.f64(double %40, double 0x3EB0C6F7A0B5ED8D, double %34)
%42 = fptosi double %41 to i32
%43 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %42)
ret i32 0
}