#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
short htons(short);
int /*<<< orphan*/ memcpy(char *, short *, int);
int /*<<< orphan*/ printf(char *);
int setNblock(short block, char *datagram) {
  char *tmp;
  if (block < 0) {
    printf("Block number is negative !\n");
    exit(EXIT_FAILURE);
  }
  tmp = datagram;
  tmp += 2;
  block = htons(block);
  memcpy(tmp, &block, sizeof(short));
  return 1;
}


x86 assembly (clang, -O0):
<setNblock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
mov    %rsi,-0x10(%rbp)
movswl -0x2(%rbp),%eax
cmp    $0x0,%eax
jge    117a <setNblock+0x3a>
lea    0xe99(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x18(%rbp)
movswl -0x2(%rbp),%edi
call   1030 <htons@plt>
mov    %ax,-0x2(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x2(%rbp),%rsi
mov    $0x2,%edx
call   1050 <memcpy@plt>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setNblock>:
push   %rbx
sub    $0x10,%rsp
test   %di,%di
js     117b <setNblock+0x3b>
mov    %rsi,%rbx
add    $0x2,%rbx
movswl %di,%edi
call   1040 <htons@plt>
mov    %ax,0xe(%rsp)
lea    0xe(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x2,%edx
call   1050 <memcpy@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe7e(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [28 x i8] c"Block number is negative !\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @setNblock(i16 signext %0, i8* %1) {
%3 = alloca i16
%4 = alloca i8*
%5 = alloca i8*
store i16 %0, i16* %3
store i8* %1, i8** %4
%6 = load i16, i16* %3
%7 = sext i16 %6 to i32
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
%12 = call i32 @exit(i32 %11)
unreachable
13: ; preds = %2
%14 = load i8*, i8** %4
store i8* %14, i8** %5
%15 = load i8*, i8** %5
%16 = getelementptr inbounds i8, i8* %15, i64 2
store i8* %16, i8** %5
%17 = load i16, i16* %3
%18 = call signext i16 @htons(i16 signext %17)
store i16 %18, i16* %3
%19 = load i8*, i8** %5
%20 = call i32 @memcpy(i8* %19, i16* %3, i32 2)
ret i32 1
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@str = [27 x i8] c"Block number is negative !\00"
define i32 @setNblock(i16 signext %0, i8* %1) {
%3 = alloca i16
%4 = icmp slt i16 %0, 0
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8, i8* %1, i64 2
%11 = tail call signext i16 @htons(i16 signext %0)
store i16 %11, i16* %3
%12 = call i32 @memcpy(i8* %10, i16* %3, i32 2)
ret i32 1
}