#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 */
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int open_socket(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ puts(char *);
int read(int, char *, int);
int /*<<< orphan*/ shutdown(int, int);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  char buffer[50000];
  int fd, ret, loop;
  if (argc <= 2) {
    puts("Usage: domain_search <domain name> <TLD> <TLD> ... ");
    exit(0);
  }
  fd = open_socket("www.uwhois.com", 999);
  for (loop = 1; loop < argc; loop++) {
    strcat(buffer, argv[loop]);
    strcat(buffer, " ");
  }
  strcat(buffer, "\n");
  ret = write(fd, buffer, strlen(buffer));
  while ((ret = read(fd, buffer, sizeof(buffer) - 1)) > 0) {
    if (write(1, buffer, ret) != ret)
      perror("write");
    fflush(stdout);
  }
  shutdown(fd, 1);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc380,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jg     11e6 <main+0x36>
lea    0xe26(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
lea    0xe47(%rip),%rdi
mov    $0x3e7,%esi
call   1060 <open_socket@plt>
mov    %eax,-0xc364(%rbp)
movl   $0x1,-0xc36c(%rbp)
mov    -0xc36c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1258 <main+0xa8>
lea    -0xc360(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0xc36c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   10c0 <strcat@plt>
lea    -0xc360(%rbp),%rdi
lea    0xdf3(%rip),%rsi
call   10c0 <strcat@plt>
mov    -0xc36c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc36c(%rbp)
jmp    1207 <main+0x57>
lea    -0xc360(%rbp),%rdi
lea    0xddd(%rip),%rsi
call   10c0 <strcat@plt>
mov    -0xc364(%rbp),%eax
mov    %eax,-0xc37c(%rbp)
lea    -0xc360(%rbp),%rax
mov    %rax,-0xc378(%rbp)
lea    -0xc360(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0xc37c(%rbp),%edi
mov    -0xc378(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %eax,-0xc368(%rbp)
mov    -0xc364(%rbp),%edi
lea    -0xc360(%rbp),%rsi
mov    $0xc34f,%edx
call   1090 <read@plt>
mov    %eax,-0xc368(%rbp)
cmp    $0x0,%eax
jle    1313 <main+0x163>
lea    -0xc360(%rbp),%rsi
mov    -0xc368(%rbp),%edx
mov    $0x1,%edi
call   1040 <write@plt>
cmp    -0xc368(%rbp),%eax
je     1300 <main+0x150>
lea    0xd4a(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2cd9(%rip),%rax
mov    (%rax),%edi
call   10a0 <fflush@plt>
jmp    12ab <main+0xfb>
mov    -0xc364(%rbp),%edi
mov    $0x1,%esi
call   1050 <shutdown@plt>
mov    -0xc364(%rbp),%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0xc380,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xc358,%rsp
cmp    $0x2,%edi
jle    12d5 <main+0x125>
mov    %rsi,%r12
mov    %edi,%ebp
lea    0xe5e(%rip),%rdi
mov    $0x3e7,%esi
call   1060 <open_socket@plt>
mov    %eax,%r15d
mov    %ebp,%r13d
mov    $0x1,%ebx
mov    %rsp,%rbp
lea    0xe3d(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r12,%rbx,8),%rsi
mov    %rbp,%rdi
call   10c0 <strcat@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   10c0 <strcat@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1200 <main+0x50>
lea    0xe1c(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   10c0 <strcat@plt>
mov    %rbx,%rdi
call   1070 <strlen@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0xc34f,%edx
call   1090 <read@plt>
test   %eax,%eax
jle    12ac <main+0xfc>
mov    %eax,%ebp
mov    %rsp,%rbx
mov    0x2d79(%rip),%r12
lea    0xdd7(%rip),%r14
jmp    128f <main+0xdf>
mov    (%r12),%edi
call   10a0 <fflush@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0xc34f,%edx
call   1090 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    12ac <main+0xfc>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1040 <write@plt>
cmp    %ebp,%eax
je     1270 <main+0xc0>
mov    %r14,%rdi
call   10b0 <perror@plt>
jmp    1270 <main+0xc0>
mov    %r15d,%edi
mov    $0x1,%esi
call   1050 <shutdown@plt>
mov    %r15d,%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0xc358,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd24(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [52 x i8] c"Usage: domain_search <domain name> <TLD> <TLD> ... \00"
@.str.1 = [15 x i8] c"www.uwhois.com\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [6 x i8] c"write\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [50000 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp sle i32 %10, 2
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 @puts(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 0)
unreachable
15: ; preds = %2
%16 = call i32 @open_socket(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 999)
store i32 %16, i32* %7
store i32 1, i32* %9
br label %17
17: ; preds = %31, %15
%18 = load i32, i32* %9
%19 = load i32, i32* %4
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %34
21: ; preds = %17
%22 = getelementptr inbounds [50000 x i8], [50000 x i8]* %6, i64 0, i64 0
%23 = load i8**, i8*** %5
%24 = load i32, i32* %9
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8*, i8** %23, i64 %25
%27 = load i8*, i8** %26
%28 = call i32 @strcat(i8* %22, i8* %27)
%29 = getelementptr inbounds [50000 x i8], [50000 x i8]* %6, i64 0, i64 0
%30 = call i32 @strcat(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %31
31: ; preds = %21
%32 = load i32, i32* %9
%33 = add nsw i32 %32, 1
store i32 %33, i32* %9
br label %17
34: ; preds = %17
%35 = getelementptr inbounds [50000 x i8], [50000 x i8]* %6, i64 0, i64 0
%36 = call i32 @strcat(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%37 = load i32, i32* %7
%38 = getelementptr inbounds [50000 x i8], [50000 x i8]* %6, i64 0, i64 0
%39 = getelementptr inbounds [50000 x i8], [50000 x i8]* %6, i64 0, i64 0
%40 = call i32 @strlen(i8* %39)
%41 = call i32 @write(i32 %37, i8* %38, i32 %40)
store i32 %41, i32* %8
br label %42
42: ; preds = %55, %34
%43 = load i32, i32* %7
%44 = getelementptr inbounds [50000 x i8], [50000 x i8]* %6, i64 0, i64 0
%45 = call i32 @read(i32 %43, i8* %44, i32 49999)
store i32 %45, i32* %8
%46 = icmp sgt i32 %45, 0
br i1 %46, label %47, label %58
47: ; preds = %42
%48 = getelementptr inbounds [50000 x i8], [50000 x i8]* %6, i64 0, i64 0
%49 = load i32, i32* %8
%50 = call i32 @write(i32 1, i8* %48, i32 %49)
%51 = load i32, i32* %8
%52 = icmp ne i32 %50, %51
br i1 %52, label %53, label %55
53: ; preds = %47
%54 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
br label %55
55: ; preds = %53, %47
%56 = load i32, i32* @stdout
%57 = call i32 @fflush(i32 %56)
br label %42
58: ; preds = %42
%59 = load i32, i32* %7
%60 = call i32 @shutdown(i32 %59, i32 1)
%61 = load i32, i32* %7
%62 = call i32 @close(i32 %61)
ret i32 0
}

LLVM IR (-O2):
@.str = [52 x i8] c"Usage: domain_search <domain name> <TLD> <TLD> ... \00"
@.str.1 = [15 x i8] c"www.uwhois.com\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [6 x i8] c"write\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [50000 x i8]
%4 = getelementptr inbounds [50000 x i8], [50000 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 3
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 0)
unreachable
9: ; preds = %2
%10 = tail call i32 @open_socket(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 999)
%11 = zext i32 %0 to i64
br label %12
12: ; preds = %9, %12
%13 = phi i64 [ 1, %9 ], [ %18, %12 ]
%14 = getelementptr inbounds i8*, i8** %1, i64 %13
%15 = load i8*, i8** %14
%16 = call i32 @strcat(i8* %4, i8* %15)
%17 = call i32 @strcat(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%18 = add nuw nsw i64 %13, 1
%19 = icmp eq i64 %18, %11
br i1 %19, label %20, label %12
20: ; preds = %12
%21 = call i32 @strcat(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%22 = call i32 @strlen(i8* %4)
%23 = call i32 @write(i32 %10, i8* %4, i32 %22)
%24 = call i32 @read(i32 %10, i8* %4, i32 49999)
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %37
26: ; preds = %20, %32
%27 = phi i32 [ %35, %32 ], [ %24, %20 ]
%28 = call i32 @write(i32 1, i8* %4, i32 %27)
%29 = icmp eq i32 %28, %27
br i1 %29, label %32, label %30
30: ; preds = %26
%31 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
br label %32
32: ; preds = %30, %26
%33 = load i32, i32* @stdout
%34 = call i32 @fflush(i32 %33)
%35 = call i32 @read(i32 %10, i8* %4, i32 49999)
%36 = icmp sgt i32 %35, 0
br i1 %36, label %26, label %37
37: ; preds = %32, %20
%38 = call i32 @shutdown(i32 %10, i32 1)
%39 = call i32 @close(i32 %10)
ret i32 0
}