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

/* Variables and functions */
int /*<<< orphan*/ *alloc_rdata_init(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ log_msg(int, char *);
int /*<<< orphan*/ strtoserial(char const *, char const **);
uint16_t *zparser_conv_serial(const char *serialstr) {
  uint16_t *r = NULL;
  uint32_t serial;
  const char *t;
  serial = strtoserial(serialstr, &t);
  if (*t != '\0') {
    log_msg(1, "serial is expected or serial too big");
  } else {
    serial = htonl(serial);
    r = alloc_rdata_init(&serial, sizeof(serial));
  }
  return r;
}


x86 assembly (clang, -O0):
<zparser_conv_serial>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <strtoserial@plt>
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     118a <zparser_conv_serial+0x4a>
mov    $0x1,%edi
lea    0xe80(%rip),%rsi
call   1060 <log_msg@plt>
jmp    11a7 <zparser_conv_serial+0x67>
mov    -0x14(%rbp),%edi
call   1040 <htonl@plt>
mov    %eax,-0x14(%rbp)
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_serial>:
sub    $0x18,%rsp
lea    0x10(%rsp),%rsi
call   1050 <strtoserial@plt>
mov    0x10(%rsp),%rcx
cmpb   $0x0,(%rcx)
je     1170 <zparser_conv_serial+0x30>
lea    0xea1(%rip),%rsi
mov    $0x1,%edi
call   1060 <log_msg@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret
mov    %eax,%edi
call   1040 <htonl@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
mov    $0x4,%esi
call   1030 <alloc_rdata_init@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [37 x i8] c"serial is expected or serial too big\00"
define i32* @zparser_conv_serial(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 i32 @strtoserial(i8* %6, i8** %5)
store i32 %7, i32* %4
%8 = load i8*, i8** %5
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = call i32 @log_msg(i32 1, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
br label %18
14: ; preds = %1
%15 = load i32, i32* %4
%16 = call i32 @htonl(i32 %15)
store i32 %16, i32* %4
%17 = call i32* @alloc_rdata_init(i32* %4, i32 4)
store i32* %17, i32** %3
br label %18
18: ; preds = %14, %12
%19 = load i32*, i32** %3
ret i32* %19
}

LLVM IR (-O2):
@.str = [37 x i8] c"serial is expected or serial too big\00"
define i32* @zparser_conv_serial(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = bitcast i32* %2 to i8*
%5 = bitcast i8** %3 to i8*
%6 = call i32 @strtoserial(i8* %0, i8** %3)
%7 = load i8*, i8** %3
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %1
%11 = call i32 @log_msg(i32 1, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
br label %15
12: ; preds = %1
%13 = call i32 @htonl(i32 %6)
store i32 %13, i32* %2
%14 = call i32* @alloc_rdata_init(i32* %2, i32 4)
br label %15
15: ; preds = %12, %10
%16 = phi i32* [ null, %10 ], [ %14, %12 ]
ret i32* %16
}