#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 ssize_t;

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int ceil(float);
scalar_t__ decode_hex(char *, scalar_t__, unsigned char *);
int /*<<< orphan*/ free(unsigned char *);
unsigned char *malloc(int);
int /*<<< orphan*/ printf(char *, unsigned char);
int /*<<< orphan*/ puts(char *);
scalar_t__ strlen(char *);
int decode(int argc, char *argv[]) {
  (void)argc;
  ssize_t outlen = ceil((float)(strlen(argv[2])) / 2.0);
  unsigned char *outbuf = malloc(outlen * sizeof(unsigned char *));
  if (outbuf == NULL) {
    return EXIT_FAILURE;
  }
  if (decode_hex(argv[2], strlen(argv[2]), outbuf) < 0) {
    free(outbuf);
    return EXIT_FAILURE;
  }
  puts("hello");
  for (int i = 0; i < outlen; ++i) {
    printf("%d\n", outbuf[i]);
  }
  free(outbuf);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<decode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1060 <strlen@plt>
cvtsi2ss %rax,%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe63(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
call   1050 <ceil@plt>
mov    %eax,-0x14(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11dc <decode+0x6c>
mov    0x2e0e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1283 <decode+0x113>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1060 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    %rax,%rsi
mov    -0x20(%rbp),%rdx
call   1080 <decode_hex@plt>
cmp    $0x0,%rax
jge    1229 <decode+0xb9>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    0x2dc1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1283 <decode+0x113>
lea    0xdd8(%rip),%rdi
call   1040 <puts@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    126e <decode+0xfe>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
lea    0xdb7(%rip),%rdi
movzbl (%rax,%rcx,1),%esi
call   1070 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    123c <decode+0xcc>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    0x2d5a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decode>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r15
mov    0x10(%rsi),%rdi
call   1060 <strlen@plt>
cvtsi2ss %rax,%xmm0
mulss  0xe6e(%rip),%xmm0
call   1050 <ceil@plt>
mov    %eax,%r14d
lea    0x0(,%r14,8),%edi
call   1090 <malloc@plt>
test   %rax,%rax
je     1218 <decode+0xa8>
mov    %rax,%r12
mov    0x10(%r15),%r15
mov    %r15,%rdi
call   1060 <strlen@plt>
mov    %r15,%rdi
mov    %rax,%rsi
mov    %r12,%rdx
call   1080 <decode_hex@plt>
test   %rax,%rax
js     1221 <decode+0xb1>
lea    0xe2f(%rip),%rdi
call   1040 <puts@plt>
mov    0x2df7(%rip),%r15
test   %r14d,%r14d
jle    1228 <decode+0xb8>
mov    %r14d,%r13d
xor    %ebx,%ebx
lea    0xe18(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl (%r12,%rbx,1),%esi
mov    %r14,%rdi
call   1070 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1200 <decode+0x90>
jmp    1228 <decode+0xb8>
mov    0x2dc1(%rip),%r15
jmp    1230 <decode+0xc0>
mov    0x2db8(%rip),%r15
mov    %r12,%rdi
call   1030 <free@plt>
mov    (%r15),%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
@.str = [6 x i8] c"hello\00"
@.str.1 = [4 x i8] c"%d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @decode(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 2
%12 = load i8*, i8** %11
%13 = call i64 @strlen(i8* %12)
%14 = sitofp i64 %13 to float
%15 = fpext float %14 to double
%16 = fdiv double %15, 2.000000e+00
%17 = fptrunc double %16 to float
%18 = call i32 @ceil(float %17)
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = sext i32 %19 to i64
%21 = mul i64 %20, 8
%22 = trunc i64 %21 to i32
%23 = call i8* @malloc(i32 %22)
store i8* %23, i8** %7
%24 = load i8*, i8** %7
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %28
26: ; preds = %2
%27 = load i32, i32* @EXIT_FAILURE
store i32 %27, i32* %3
br label %63
28: ; preds = %2
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 2
%31 = load i8*, i8** %30
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 2
%34 = load i8*, i8** %33
%35 = call i64 @strlen(i8* %34)
%36 = load i8*, i8** %7
%37 = call i64 @decode_hex(i8* %31, i64 %35, i8* %36)
%38 = icmp slt i64 %37, 0
br i1 %38, label %39, label %43
39: ; preds = %28
%40 = load i8*, i8** %7
%41 = call i32 @free(i8* %40)
%42 = load i32, i32* @EXIT_FAILURE
store i32 %42, i32* %3
br label %63
43: ; preds = %28
%44 = call i32 @puts(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %8
br label %45
45: ; preds = %56, %43
%46 = load i32, i32* %8
%47 = load i32, i32* %6
%48 = icmp slt i32 %46, %47
br i1 %48, label %49, label %59
49: ; preds = %45
%50 = load i8*, i8** %7
%51 = load i32, i32* %8
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %50, i64 %52
%54 = load i8, i8* %53
%55 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %54)
br label %56
56: ; preds = %49
%57 = load i32, i32* %8
%58 = add nsw i32 %57, 1
store i32 %58, i32* %8
br label %45
59: ; preds = %45
%60 = load i8*, i8** %7
%61 = call i32 @free(i8* %60)
%62 = load i32, i32* @EXIT_SUCCESS
store i32 %62, i32* %3
br label %63
63: ; preds = %59, %39, %26
%64 = load i32, i32* %3
ret i32 %64
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str = [6 x i8] c"hello\00"
@.str.1 = [4 x i8] c"%d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @decode(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 2
%4 = load i8*, i8** %3
%5 = tail call i64 @strlen(i8* dereferenceable(1) %4)
%6 = sitofp i64 %5 to float
%7 = fmul float %6, 5.000000e-01
%8 = tail call i32 @ceil(float %7)
%9 = shl i32 %8, 3
%10 = tail call i8* @malloc(i32 %9)
%11 = icmp eq i8* %10, null
br i1 %11, label %32, label %12
12: ; preds = %2
%13 = load i8*, i8** %3
%14 = tail call i64 @strlen(i8* dereferenceable(1) %13)
%15 = tail call i64 @decode_hex(i8* %13, i64 %14, i8* %10)
%16 = icmp slt i64 %15, 0
br i1 %16, label %29, label %17
17: ; preds = %12
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%19 = icmp sgt i32 %8, 0
br i1 %19, label %20, label %29
20: ; preds = %17
%21 = zext i32 %8 to i64
br label %22
22: ; preds = %20, %22
%23 = phi i64 [ 0, %20 ], [ %27, %22 ]
%24 = getelementptr inbounds i8, i8* %10, i64 %23
%25 = load i8, i8* %24
%26 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %25)
%27 = add nuw nsw i64 %23, 1
%28 = icmp eq i64 %27, %21
br i1 %28, label %29, label %22
29: ; preds = %22, %17, %12
%30 = phi i32* [ @EXIT_FAILURE, %12 ], [ @EXIT_SUCCESS, %17 ], [ @EXIT_SUCCESS, %22 ]
%31 = tail call i32 @free(i8* %10)
br label %32
32: ; preds = %29, %2
%33 = phi i32* [ @EXIT_FAILURE, %2 ], [ %30, %29 ]
%34 = load i32, i32* %33
ret i32 %34
}