#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 */
size_t strlen(char const *);
size_t string2data_size(const char *string) {
  size_t length;
  size_t size;
  if (string == NULL)
    return 0;
  length = strlen(string);
  if (length == 0)
    return 0;
  if (length % 2 == 0)
    size = length / 2;
  else
    size = (length - (length % 2)) / 2 + 1;
  return size;
}


x86 assembly (clang, -O0):
<string2data_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1134 <string2data_size+0x24>
movq   $0x0,-0x8(%rbp)
jmp    119f <string2data_size+0x8f>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1159 <string2data_size+0x49>
movq   $0x0,-0x8(%rbp)
jmp    119f <string2data_size+0x8f>
mov    -0x18(%rbp),%rax
and    $0x1,%rax
cmp    $0x0,%rax
jne    117c <string2data_size+0x6c>
mov    -0x18(%rbp),%rax
shr    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1197 <string2data_size+0x87>
mov    -0x18(%rbp),%rax
mov    -0x18(%rbp),%rcx
and    $0x1,%rcx
sub    %rcx,%rax
shr    $0x1,%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string2data_size>:
test   %rdi,%rdi
je     1141 <string2data_size+0x31>
push   %rax
call   1030 <strlen@plt>
test   %rax,%rax
lea    0x8(%rsp),%rsp
je     1141 <string2data_size+0x31>
mov    %rax,%rcx
mov    %rax,%rdx
shr    %rdx
add    $0xffffffffffffffff,%rax
shr    %rax
add    $0x1,%rax
test   $0x1,%cl
cmove  %rdx,%rax
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
define i64 @string2data_size(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %9
8: ; preds = %1
store i64 0, i64* %2
br label %31
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i64 @strlen(i8* %10)
store i64 %11, i64* %4
%12 = load i64, i64* %4
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %9
store i64 0, i64* %2
br label %31
15: ; preds = %9
%16 = load i64, i64* %4
%17 = urem i64 %16, 2
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = load i64, i64* %4
%21 = udiv i64 %20, 2
store i64 %21, i64* %5
br label %29
22: ; preds = %15
%23 = load i64, i64* %4
%24 = load i64, i64* %4
%25 = urem i64 %24, 2
%26 = sub i64 %23, %25
%27 = udiv i64 %26, 2
%28 = add i64 %27, 1
store i64 %28, i64* %5
br label %29
29: ; preds = %22, %19
%30 = load i64, i64* %5
store i64 %30, i64* %2
br label %31
31: ; preds = %29, %14, %8
%32 = load i64, i64* %2
ret i64 %32
}

LLVM IR (-O2):
define i64 @string2data_size(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %14, label %3
3: ; preds = %1
%4 = tail call i64 @strlen(i8* %0)
%5 = icmp eq i64 %4, 0
br i1 %5, label %14, label %6
6: ; preds = %3
%7 = and i64 %4, 1
%8 = icmp eq i64 %7, 0
%9 = lshr i64 %4, 1
%10 = add i64 %4, -1
%11 = lshr i64 %10, 1
%12 = add nuw i64 %11, 1
%13 = select i1 %8, i64 %9, i64 %12
br label %14
14: ; preds = %3, %1, %6
%15 = phi i64 [ %13, %6 ], [ 0, %1 ], [ 0, %3 ]
ret i64 %15
}