#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 */
typedef int /*<<< orphan*/ value;
typedef int /*<<< orphan*/ uint16_t;

/* Variables and functions */
int /*<<< orphan*/ *alloc_rdata_init(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ log_msg(int, char *);
scalar_t__ strtol(char const *, char **, int);
uint16_t *zparser_conv_short(const char *text) {
  uint16_t *r = NULL;
  uint16_t value;
  char *end;
  value = htons((uint16_t)strtol(text, &end, 10));
  if (*end != '\0') {
    log_msg(1, "integer value is expected");
  } else {
    r = alloc_rdata_init(&value, sizeof(value));
  }
  return r;
}


x86 assembly (clang, -O0):
<zparser_conv_short>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,%edi
call   1040 <htons@plt>
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1196 <zparser_conv_short+0x56>
mov    $0x1,%edi
lea    0xe74(%rip),%rsi
call   1060 <log_msg@plt>
jmp    11a8 <zparser_conv_short+0x68>
lea    -0x14(%rbp),%rdi
mov    $0x4,%esi
call   1030 <alloc_rdata_init@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zparser_conv_short>:
sub    $0x18,%rsp
lea    0x10(%rsp),%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,%edi
call   1040 <htons@plt>
mov    %eax,0xc(%rsp)
mov    0x10(%rsp),%rax
cmpb   $0x0,(%rax)
je     1180 <zparser_conv_short+0x40>
lea    0xe91(%rip),%rsi
mov    $0x1,%edi
call   1060 <log_msg@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret
lea    0xc(%rsp),%rdi
mov    $0x4,%esi
call   1030 <alloc_rdata_init@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"integer value is expected\00"
define i32* @zparser_conv_short(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %2
store i32* null, i32** %3
%6 = load i8*, i8** %2
%7 = call i64 @strtol(i8* %6, i8** %5, i32 10)
%8 = trunc i64 %7 to i32
%9 = call i32 @htons(i32 %8)
store i32 %9, i32* %4
%10 = load i8*, i8** %5
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %1
%15 = call i32 @log_msg(i32 1, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %18
16: ; preds = %1
%17 = call i32* @alloc_rdata_init(i32* %4, i32 4)
store i32* %17, i32** %3
br label %18
18: ; preds = %16, %14
%19 = load i32*, i32** %3
ret i32* %19
}

LLVM IR (-O2):
@.str = [26 x i8] c"integer value is expected\00"
define i32* @zparser_conv_short(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = bitcast i32* %2 to i8*
%5 = bitcast i8** %3 to i8*
%6 = call i64 @strtol(i8* %0, i8** %3, i32 10)
%7 = trunc i64 %6 to i32
%8 = tail call i32 @htons(i32 %7)
store i32 %8, i32* %2
%9 = load i8*, i8** %3
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %1
%13 = tail call i32 @log_msg(i32 1, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %16
14: ; preds = %1
%15 = call i32* @alloc_rdata_init(i32* %2, i32 4)
br label %16
16: ; preds = %14, %12
%17 = phi i32* [ null, %12 ], [ %15, %14 ]
ret i32* %17
}