#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 */

/* Variables and functions */
int /*<<< orphan*/ close(int);
int listen_loop(int, char *);
int /*<<< orphan*/ printf(char *);
int udp_sock();
int main(int argc, char *argv[]) {
  int rc;
  int ret = 0;
  int sock = udp_sock();
  if (argc < 2) {
    printf("no hostname given\n");
    ret = 1;
    goto out;
  }
  if (sock == -1) {
    printf("sock err\n");
    ret = 1;
    goto out;
  }
  rc = listen_loop(sock, argv[1]);
  if (rc == -1) {
    ret = 1;
    goto out;
  }
out:
  if (sock != -1) {
    close(sock);
  }
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    $0x0,%al
call   1060 <udp_sock@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1189 <main+0x49>
lea    0xe88(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x18(%rbp)
jmp    11d9 <main+0x99>
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11ab <main+0x6b>
lea    0xe79(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x18(%rbp)
jmp    11d9 <main+0x99>
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <listen_loop@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11d4 <main+0x94>
movl   $0x1,-0x18(%rbp)
jmp    11d9 <main+0x99>
jmp    11d9 <main+0x99>
cmpl   $0xffffffff,-0x1c(%rbp)
je     11eb <main+0xab>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebp
xor    %eax,%eax
call   1060 <udp_sock@plt>
mov    %eax,%ebx
cmp    $0x2,%ebp
jge    116f <main+0x2f>
lea    0xeab(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%ebp
cmp    $0xffffffff,%ebx
jne    1188 <main+0x48>
jmp    11a2 <main+0x62>
cmp    $0xffffffff,%ebx
je     1191 <main+0x51>
mov    0x8(%r14),%rsi
mov    %ebx,%edi
call   1030 <listen_loop@plt>
xor    %ebp,%ebp
cmp    $0xffffffff,%eax
sete   %bpl
mov    %ebx,%edi
call   1050 <close@plt>
jmp    11a2 <main+0x62>
lea    0xe68(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"no hostname given\0A\00"
@.str.1 = [10 x i8] c"sock err\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
%9 = call i32 (...) @udp_sock()
store i32 %9, i32* %8
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %7
br label %29
14: ; preds = %2
%15 = load i32, i32* %8
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %7
br label %29
19: ; preds = %14
%20 = load i32, i32* %8
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32 @listen_loop(i32 %20, i8* %23)
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %28
27: ; preds = %19
store i32 1, i32* %7
br label %29
28: ; preds = %19
br label %29
29: ; preds = %28, %27, %17, %12
%30 = load i32, i32* %8
%31 = icmp ne i32 %30, -1
br i1 %31, label %32, label %35
32: ; preds = %29
%33 = load i32, i32* %8
%34 = call i32 @close(i32 %33)
br label %35
35: ; preds = %32, %29
%36 = load i32, i32* %7
ret i32 %36
}

LLVM IR (-O2):
@str = [9 x i8] c"sock err\00"
@str.2 = [18 x i8] c"no hostname given\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 (...) @udp_sock()
%4 = icmp slt i32 %0, 2
br i1 %4, label %15, label %5
5: ; preds = %2
%6 = icmp eq i32 %3, -1
br i1 %6, label %7, label %9
7: ; preds = %5
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
br label %21
9: ; preds = %5
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @listen_loop(i32 %3, i8* %11)
%13 = icmp eq i32 %12, -1
%14 = zext i1 %13 to i32
br label %18
15: ; preds = %2
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.2, i64 0, i64 0))
%17 = icmp eq i32 %3, -1
br i1 %17, label %21, label %18
18: ; preds = %9, %15
%19 = phi i32 [ %14, %9 ], [ 1, %15 ]
%20 = tail call i32 @close(i32 %3)
br label %21
21: ; preds = %7, %18, %15
%22 = phi i32 [ 1, %7 ], [ %19, %18 ], [ 1, %15 ]
ret i32 %22
}