#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ servaddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ printf(char *, ...);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  int sockfd, n;
  struct sockaddr_in servaddr;
  socklen_t addrlen = sizeof(servaddr);
  int recvlen;
  char json[100];
  sockfd = socket(AF_INET, SOCK_DGRAM, 0);
  bzero(&servaddr, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_addr.s_addr = inet_addr("127.0.0.1");
  servaddr.sin_port = htons(41235);
  if (bind(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0) {
    printf("Bind failed");
    return 0;
  }
  printf("Listening...\n");
  fflush(stdout);
  recvlen =
      recvfrom(sockfd, json, 100, 0, (struct sockaddr *)&servaddr, &addrlen);
  printf("Received actuation: %s\n", json);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xc,-0x2c(%rbp)
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
mov    0x2e30(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x14(%rbp)
lea    -0x28(%rbp),%rdi
mov    $0xc,%esi
call   1090 <bzero@plt>
mov    0x2e17(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
lea    0xe23(%rip),%rdi
call   1050 <inet_addr@plt>
mov    %eax,-0x24(%rbp)
mov    $0xa113,%edi
call   1030 <htons@plt>
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   1080 <bind@plt>
cmp    $0x0,%rax
jge    1227 <main+0xa7>
lea    0xdf6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1280 <main+0x100>
lea    0xde8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    -0x14(%rbp),%edi
lea    -0xa0(%rbp),%rsi
lea    -0x28(%rbp),%r8
mov    $0x64,%edx
xor    %ecx,%ecx
lea    -0x2c(%rbp),%r9
call   1070 <recvfrom@plt>
mov    %eax,-0x30(%rbp)
lea    -0xa0(%rbp),%rsi
lea    0xdb2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x90,%rsp
movl   $0xc,0xc(%rsp)
mov    0x2e3e(%rip),%rbx
mov    (%rbx),%edi
mov    0x2e2d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,%ebp
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0xc,%esi
call   10a0 <bzero@plt>
mov    (%rbx),%eax
mov    %eax,0x18(%rsp)
lea    0xe23(%rip),%rdi
call   1060 <inet_addr@plt>
mov    %eax,0x14(%rsp)
mov    $0xa113,%edi
call   1040 <htons@plt>
mov    %eax,0x10(%rsp)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   1090 <bind@plt>
test   %rax,%rax
js     1255 <main+0xc5>
lea    0xe1f(%rip),%rdi
call   1030 <puts@plt>
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
lea    0x20(%rsp),%r14
lea    0x10(%rsp),%r8
lea    0xc(%rsp),%r9
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
call   1080 <recvfrom@plt>
lea    0xdcd(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1263 <main+0xd3>
lea    0xdae(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [12 x i8] c"Bind failed\00"
@.str.2 = [14 x i8] c"Listening...\0A\00"
@stdout = global i32 0
@.str.3 = [24 x i8] c"Received actuation: %s\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 %struct.sockaddr_in
%9 = alloca i32
%10 = alloca i32
%11 = alloca [100 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 12, i32* %9
%12 = load i32, i32* @AF_INET
%13 = load i32, i32* @SOCK_DGRAM
%14 = call i32 @socket(i32 %12, i32 %13, i32 0)
store i32 %14, i32* %6
%15 = call i32 @bzero(%struct.sockaddr_in* %8, i32 12)
%16 = load i32, i32* @AF_INET
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %16, i32* %17
%18 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
%20 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %19, i32 0, i32 0
store i32 %18, i32* %20
%21 = call i32 @htons(i32 41235)
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
store i32 %21, i32* %22
%23 = load i32, i32* %6
%24 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%25 = call i64 @bind(i32 %23, %struct.sockaddr* %24, i32 12)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %2
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %39
29: ; preds = %2
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%31 = load i32, i32* @stdout
%32 = call i32 @fflush(i32 %31)
%33 = load i32, i32* %6
%34 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%35 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%36 = call i32 @recvfrom(i32 %33, i8* %34, i32 100, i32 0, %struct.sockaddr* %35, i32* %9)
store i32 %36, i32* %10
%37 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %37)
store i32 0, i32* %3
br label %39
39: ; preds = %29, %27
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [12 x i8] c"Bind failed\00"
@stdout = global i32 0
@.str.3 = [24 x i8] c"Received actuation: %s\0A\00"
@str = [13 x i8] c"Listening...\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca [100 x i8]
%6 = bitcast %struct.sockaddr_in* %3 to i8*
%7 = bitcast i32* %4 to i8*
store i32 12, i32* %4
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_DGRAM
%11 = tail call i32 @socket(i32 %9, i32 %10, i32 0)
%12 = call i32 @bzero(%struct.sockaddr_in* %3, i32 12)
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %13, i32* %14
%15 = tail call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %15, i32* %16
%17 = tail call i32 @htons(i32 41235)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %17, i32* %18
%19 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%20 = call i64 @bind(i32 %11, %struct.sockaddr* %19, i32 12)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %2
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %30
24: ; preds = %2
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%26 = load i32, i32* @stdout
%27 = call i32 @fflush(i32 %26)
%28 = call i32 @recvfrom(i32 %11, i8* %8, i32 100, i32 0, %struct.sockaddr* %19, i32* %4)
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %8)
br label %30
30: ; preds = %24, %22
ret i32 0
}