#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 addrinfo {
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_addr;
  int /*<<< orphan*/ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
  struct addrinfo *ai_next;
  int /*<<< orphan*/ ai_flags;
};
typedef int /*<<< orphan*/ socklen_t;

/* Variables and functions */
int /*<<< orphan*/ AF_UNSPEC;
int /*<<< orphan*/ AI_PASSIVE;
int /*<<< orphan*/ SOCK_DGRAM;
scalar_t__ bind(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *,
                           char const *, char const *, ...);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
char *gai_strerror(int);
int getaddrinfo(char const *, char const *, struct addrinfo *,
                struct addrinfo **);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int udp_server(const char *host, const char *serv, socklen_t *addrlenp) {
  int sockfd;
  int n;
  struct addrinfo hints;
  struct addrinfo *res;
  struct addrinfo *ressave;
  memset(&hints, 0, sizeof(struct addrinfo));
  hints.ai_flags = AI_PASSIVE;
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_DGRAM;
  if ((n = getaddrinfo(host, serv, &hints, &res)) != 0) {
    fprintf(stderr, "udp_server error for %s , %s:%s [%s,%d]\n",
            gai_strerror(n), host, serv,
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/yuikns/unpbt/refs/heads/master/lib/"
            "argcvnw/argcvnw.c",
            220);
    return 0;
  }
  ressave = res;
  do {
    sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
    if (sockfd < 0)
      continue;
    if (bind(sockfd, res->ai_addr, res->ai_addrlen) == 0)
      break;
    close(sockfd);
  } while ((res = res->ai_next) != NULL);
  if (res == NULL) {
    fprintf(stderr, "udp_server error for %s:%s [%s,%d]\n", host, serv,
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/yuikns/unpbt/refs/heads/master/lib/"
            "argcvnw/argcvnw.c",
            237);
    return 0;
  }
  if (addrlenp)
    *addrlenp = res->ai_addrlen;
  freeaddrinfo(ressave);
  return sockfd;
}


x86 assembly (clang, -O0):
<udp_server>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
mov    0x2e3d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2e29(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    0x2e15(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x50(%rbp),%rdx
lea    -0x58(%rbp),%rcx
call   1080 <getaddrinfo@plt>
mov    %eax,-0x28(%rbp)
cmp    $0x0,%eax
je     1233 <udp_server+0xb3>
mov    0x2dd8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    -0x28(%rbp),%edi
call   1030 <gai_strerror@plt>
mov    -0x64(%rbp),%edi
mov    %rax,%rdx
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
lea    0xdee(%rip),%rsi
lea    0xe10(%rip),%r9
movl   $0xdc,(%rsp)
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1312 <udp_server+0x192>
mov    -0x58(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x58(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x58(%rbp),%rax
mov    0xc(%rax),%esi
mov    -0x58(%rbp),%rax
mov    0x8(%rax),%edx
call   10a0 <socket@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1267 <udp_server+0xe7>
jmp    1293 <udp_server+0x113>
mov    -0x24(%rbp),%edi
mov    -0x58(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x58(%rbp),%rax
mov    (%rax),%edx
call   1070 <bind@plt>
cmp    $0x0,%rax
jne    128b <udp_server+0x10b>
jmp    12a9 <udp_server+0x129>
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
mov    -0x58(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x58(%rbp)
cmp    $0x0,%rax
jne    123b <udp_server+0xbb>
cmpq   $0x0,-0x58(%rbp)
jne    12ec <udp_server+0x16c>
mov    0x2d0d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xdec(%rip),%rsi
lea    0xd56(%rip),%r8
mov    $0xed,%r9d
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1312 <udp_server+0x192>
cmpq   $0x0,-0x20(%rbp)
je     1303 <udp_server+0x183>
mov    -0x58(%rbp),%rax
mov    (%rax),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x60(%rbp),%rdi
call   1090 <freeaddrinfo@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<udp_server>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r13
lea    0x10(%rsp),%rbx
xor    %ebp,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
mov    0x2e34(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x30(%rsp)
mov    0x2e1f(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x20(%rsp)
mov    0x2e0a(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x1c(%rsp)
lea    0x8(%rsp),%rcx
mov    %r13,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1080 <getaddrinfo@plt>
test   %eax,%eax
je     1227 <udp_server+0xa7>
mov    0x2dd6(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1030 <gai_strerror@plt>
movl   $0xdc,(%rsp)
lea    0xdf7(%rip),%rsi
lea    0xe19(%rip),%r9
mov    %ebx,%edi
mov    %rax,%rdx
mov    %r13,%rcx
mov    %r14,%r8
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    12d0 <udp_server+0x150>
mov    0x8(%rsp),%r12
mov    %r12,%rax
jmp    1253 <udp_server+0xd3>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rax
mov    0x18(%rax),%rax
mov    %rax,0x8(%rsp)
test   %rax,%rax
je     12a4 <udp_server+0x124>
mov    0x10(%rax),%edi
mov    0x8(%rax),%edx
mov    0xc(%rax),%esi
call   10a0 <socket@plt>
test   %eax,%eax
js     1240 <udp_server+0xc0>
mov    %eax,%ebp
mov    0x8(%rsp),%rax
mov    (%rax),%edx
mov    0x4(%rax),%esi
mov    %ebp,%edi
call   1070 <bind@plt>
test   %rax,%rax
je     1286 <udp_server+0x106>
mov    %ebp,%edi
call   1050 <close@plt>
jmp    1240 <udp_server+0xc0>
mov    0x8(%rsp),%rax
test   %rax,%rax
je     12a4 <udp_server+0x124>
test   %r15,%r15
je     129a <udp_server+0x11a>
mov    (%rax),%eax
mov    %eax,(%r15)
mov    %r12,%rdi
call   1090 <freeaddrinfo@plt>
jmp    12d0 <udp_server+0x150>
mov    0x2d1d(%rip),%rax
mov    (%rax),%edi
lea    0xe04(%rip),%rsi
lea    0xd6e(%rip),%r8
xor    %ebp,%ebp
mov    %r13,%rdx
mov    %r14,%rcx
mov    $0xed,%r9d
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %ebp,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i32, i32, i32, %struct.addrinfo*, i32 }
@AI_PASSIVE = global i32 0
@AF_UNSPEC = global i32 0
@SOCK_DGRAM = global i32 0
@stderr = global i32 0
@.str = [41 x i8] c"udp_server error for %s , %s:%s [%s,%d]\0A\00"
@.str.1 = [143 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/yuikns/unpbt/refs/heads/master/lib/argcvnw/argcvnw.c\00"
@.str.2 = [36 x i8] c"udp_server error for %s:%s [%s,%d]\0A\00"
define i32 @udp_server(i8* %0, i8* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.addrinfo
%11 = alloca %struct.addrinfo*
%12 = alloca %struct.addrinfo*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32* %2, i32** %7
%13 = call i32 @memset(%struct.addrinfo* %10, i32 0, i32 40)
%14 = load i32, i32* @AI_PASSIVE
%15 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %10, i32 0, i32 6
store i32 %14, i32* %15
%16 = load i32, i32* @AF_UNSPEC
%17 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %10, i32 0, i32 4
store i32 %16, i32* %17
%18 = load i32, i32* @SOCK_DGRAM
%19 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %10, i32 0, i32 3
store i32 %18, i32* %19
%20 = load i8*, i8** %5
%21 = load i8*, i8** %6
%22 = call i32 @getaddrinfo(i8* %20, i8* %21, %struct.addrinfo* %10, %struct.addrinfo** %11)
store i32 %22, i32* %9
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %31
24: ; preds = %3
%25 = load i32, i32* @stderr
%26 = load i32, i32* %9
%27 = call i8* @gai_strerror(i32 %26)
%28 = load i8*, i8** %5
%29 = load i8*, i8** %6
%30 = call i32 (i32, i8*, i8*, i8*, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %27, i8* %28, i8* %29, i8* getelementptr inbounds ([143 x i8], [143 x i8]* @.str.1, i64 0, i64 0), i32 220)
store i32 0, i32* %4
br label %86
31: ; preds = %3
%32 = load %struct.addrinfo*, %struct.addrinfo** %11
store %struct.addrinfo* %32, %struct.addrinfo** %12
br label %33
33: ; preds = %61, %31
%34 = load %struct.addrinfo*, %struct.addrinfo** %11
%35 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %34, i32 0, i32 4
%36 = load i32, i32* %35
%37 = load %struct.addrinfo*, %struct.addrinfo** %11
%38 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %37, i32 0, i32 3
%39 = load i32, i32* %38
%40 = load %struct.addrinfo*, %struct.addrinfo** %11
%41 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %40, i32 0, i32 2
%42 = load i32, i32* %41
%43 = call i32 @socket(i32 %36, i32 %39, i32 %42)
store i32 %43, i32* %8
%44 = load i32, i32* %8
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %33
br label %61
47: ; preds = %33
%48 = load i32, i32* %8
%49 = load %struct.addrinfo*, %struct.addrinfo** %11
%50 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %49, i32 0, i32 1
%51 = load i32, i32* %50
%52 = load %struct.addrinfo*, %struct.addrinfo** %11
%53 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %52, i32 0, i32 0
%54 = load i32, i32* %53
%55 = call i64 @bind(i32 %48, i32 %51, i32 %54)
%56 = icmp eq i64 %55, 0
br i1 %56, label %57, label %58
57: ; preds = %47
br label %66
58: ; preds = %47
%59 = load i32, i32* %8
%60 = call i32 @close(i32 %59)
br label %61
61: ; preds = %58, %46
%62 = load %struct.addrinfo*, %struct.addrinfo** %11
%63 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %62, i32 0, i32 5
%64 = load %struct.addrinfo*, %struct.addrinfo** %63
store %struct.addrinfo* %64, %struct.addrinfo** %11
%65 = icmp ne %struct.addrinfo* %64, null
br i1 %65, label %33, label %66
66: ; preds = %61, %57
%67 = load %struct.addrinfo*, %struct.addrinfo** %11
%68 = icmp eq %struct.addrinfo* %67, null
br i1 %68, label %69, label %74
69: ; preds = %66
%70 = load i32, i32* @stderr
%71 = load i8*, i8** %5
%72 = load i8*, i8** %6
%73 = call i32 (i32, i8*, i8*, i8*, i8*, ...) @fprintf(i32 %70, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %71, i8* %72, i8* getelementptr inbounds ([143 x i8], [143 x i8]* @.str.1, i64 0, i64 0), i32 237)
store i32 0, i32* %4
br label %86
74: ; preds = %66
%75 = load i32*, i32** %7
%76 = icmp ne i32* %75, null
br i1 %76, label %77, label %82
77: ; preds = %74
%78 = load %struct.addrinfo*, %struct.addrinfo** %11
%79 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %78, i32 0, i32 0
%80 = load i32, i32* %79
%81 = load i32*, i32** %7
store i32 %80, i32* %81
br label %82
82: ; preds = %77, %74
%83 = load %struct.addrinfo*, %struct.addrinfo** %12
%84 = call i32 @freeaddrinfo(%struct.addrinfo* %83)
%85 = load i32, i32* %8
store i32 %85, i32* %4
br label %86
86: ; preds = %82, %69, %24
%87 = load i32, i32* %4
ret i32 %87
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32, i32, i32, %struct.addrinfo*, i32 }
@AI_PASSIVE = global i32 0
@AF_UNSPEC = global i32 0
@SOCK_DGRAM = global i32 0
@stderr = global i32 0
@.str = [41 x i8] c"udp_server error for %s , %s:%s [%s,%d]\0A\00"
@.str.1 = [143 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/yuikns/unpbt/refs/heads/master/lib/argcvnw/argcvnw.c\00"
@.str.2 = [36 x i8] c"udp_server error for %s:%s [%s,%d]\0A\00"
define i32 @udp_server(i8* %0, i8* %1, i32* writeonly %2) {
%4 = alloca %struct.addrinfo
%5 = alloca %struct.addrinfo*
%6 = bitcast %struct.addrinfo* %4 to i8*
%7 = bitcast %struct.addrinfo** %5 to i8*
%8 = call i32 @memset(%struct.addrinfo* %4, i32 0, i32 40)
%9 = load i32, i32* @AI_PASSIVE
%10 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 6
store i32 %9, i32* %10
%11 = load i32, i32* @AF_UNSPEC
%12 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 4
store i32 %11, i32* %12
%13 = load i32, i32* @SOCK_DGRAM
%14 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 3
store i32 %13, i32* %14
%15 = call i32 @getaddrinfo(i8* %0, i8* %1, %struct.addrinfo* %4, %struct.addrinfo** %5)
%16 = icmp eq i32 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %3
%18 = load i32, i32* @stderr
%19 = call i8* @gai_strerror(i32 %15)
%20 = call i32 (i32, i8*, i8*, i8*, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %19, i8* %0, i8* %1, i8* getelementptr inbounds ([143 x i8], [143 x i8]* @.str.1, i64 0, i64 0), i32 220)
br label %61
21: ; preds = %3
%22 = load %struct.addrinfo*, %struct.addrinfo** %5
br label %23
23: ; preds = %43, %21
%24 = phi %struct.addrinfo* [ %46, %43 ], [ %22, %21 ]
%25 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %24, i64 0, i32 4
%26 = load i32, i32* %25
%27 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %24, i64 0, i32 3
%28 = load i32, i32* %27
%29 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %24, i64 0, i32 2
%30 = load i32, i32* %29
%31 = call i32 @socket(i32 %26, i32 %28, i32 %30)
%32 = icmp slt i32 %31, 0
br i1 %32, label %43, label %33
33: ; preds = %23
%34 = load %struct.addrinfo*, %struct.addrinfo** %5
%35 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %34, i64 0, i32 1
%36 = load i32, i32* %35
%37 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %34, i64 0, i32 0
%38 = load i32, i32* %37
%39 = call i64 @bind(i32 %31, i32 %36, i32 %38)
%40 = icmp eq i64 %39, 0
br i1 %40, label %48, label %41
41: ; preds = %33
%42 = call i32 @close(i32 %31)
br label %43
43: ; preds = %23, %41
%44 = load %struct.addrinfo*, %struct.addrinfo** %5
%45 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %44, i64 0, i32 5
%46 = load %struct.addrinfo*, %struct.addrinfo** %45
store %struct.addrinfo* %46, %struct.addrinfo** %5
%47 = icmp eq %struct.addrinfo* %46, null
br i1 %47, label %51, label %23
48: ; preds = %33
%49 = load %struct.addrinfo*, %struct.addrinfo** %5
%50 = icmp eq %struct.addrinfo* %49, null
br i1 %50, label %51, label %54
51: ; preds = %43, %48
%52 = load i32, i32* @stderr
%53 = call i32 (i32, i8*, i8*, i8*, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %1, i8* getelementptr inbounds ([143 x i8], [143 x i8]* @.str.1, i64 0, i64 0), i32 237)
br label %61
54: ; preds = %48
%55 = icmp eq i32* %2, null
br i1 %55, label %59, label %56
56: ; preds = %54
%57 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %49, i64 0, i32 0
%58 = load i32, i32* %57
store i32 %58, i32* %2
br label %59
59: ; preds = %56, %54
%60 = call i32 @freeaddrinfo(%struct.addrinfo* %22)
br label %61
61: ; preds = %59, %51, %17
%62 = phi i32 [ 0, %17 ], [ 0, %51 ], [ %31, %59 ]
ret i32 %62
}