#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);
int udp_sock(int);
int main(int argc, char *argv[]) {
  int rc;
  int ret = 0;
  int sock = udp_sock(1234);
  if (sock == -1) {
    ret = 1;
    goto out;
  }
  rc = listen_loop(sock);
  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    $0x4d2,%edi
call   1050 <udp_sock@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1170 <main+0x40>
movl   $0x1,-0x18(%rbp)
jmp    1196 <main+0x66>
mov    -0x1c(%rbp),%edi
call   1030 <listen_loop@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1191 <main+0x61>
movl   $0x1,-0x18(%rbp)
jmp    1196 <main+0x66>
jmp    1196 <main+0x66>
cmpl   $0xffffffff,-0x1c(%rbp)
je     11a8 <main+0x78>
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    $0x4d2,%edi
call   1050 <udp_sock@plt>
cmp    $0xffffffff,%eax
je     115d <main+0x2d>
mov    %eax,%ebx
mov    %eax,%edi
call   1030 <listen_loop@plt>
xor    %ebp,%ebp
cmp    $0xffffffff,%eax
sete   %bpl
mov    %ebx,%edi
call   1040 <close@plt>
jmp    1162 <main+0x32>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
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(i32 1234)
store i32 %9, i32* %8
%10 = load i32, i32* %8
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 1, i32* %7
br label %20
13: ; preds = %2
%14 = load i32, i32* %8
%15 = call i32 @listen_loop(i32 %14)
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %19
18: ; preds = %13
store i32 1, i32* %7
br label %20
19: ; preds = %13
br label %20
20: ; preds = %19, %18, %12
%21 = load i32, i32* %8
%22 = icmp ne i32 %21, -1
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = load i32, i32* %8
%25 = call i32 @close(i32 %24)
br label %26
26: ; preds = %23, %20
%27 = load i32, i32* %7
ret i32 %27
}

LLVM IR (-O2):
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @udp_sock(i32 1234)
%4 = icmp eq i32 %3, -1
br i1 %4, label %10, label %5
5: ; preds = %2
%6 = tail call i32 @listen_loop(i32 %3)
%7 = icmp eq i32 %6, -1
%8 = zext i1 %7 to i32
%9 = tail call i32 @close(i32 %3)
br label %10
10: ; preds = %2, %5
%11 = phi i32 [ %8, %5 ], [ 1, %2 ]
ret i32 %11
}