#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*/ free(char *);
int sscanf(char *, char *, char *);
scalar_t__ strlen(char *);
char *xmalloc(scalar_t__);
char *clean_month(char *s) {
  if ((s == NULL) || (*s == '\0'))
    return NULL;
  char *buffer = xmalloc(strlen(s) + 1);
  if (sscanf(s, "%6[^|]", buffer) != 1) {
    free(buffer);
    return NULL;
  }
  return buffer;
}


x86 assembly (clang, -O0):
<clean_month>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1167 <clean_month+0x27>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1174 <clean_month+0x34>
movq   $0x0,-0x8(%rbp)
jmp    11c8 <clean_month+0x88>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1050 <xmalloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe64(%rip),%rsi
call   1060 <sscanf@plt>
cmp    $0x1,%eax
je     11c0 <clean_month+0x80>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    11c8 <clean_month+0x88>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clean_month>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1184 <clean_month+0x44>
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     1184 <clean_month+0x44>
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdi
call   1050 <xmalloc@plt>
mov    %rax,%r14
lea    0xe94(%rip),%rsi
mov    %rbx,%rdi
mov    %rax,%rdx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
je     1187 <clean_month+0x47>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%6[^|]\00"
define i8* @clean_month(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = icmp eq i8* %5, null
br i1 %6, label %12, label %7
7: ; preds = %1
%8 = load i8*, i8** %3
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %7, %1
store i8* null, i8** %2
br label %27
13: ; preds = %7
%14 = load i8*, i8** %3
%15 = call i64 @strlen(i8* %14)
%16 = add nsw i64 %15, 1
%17 = call i8* @xmalloc(i64 %16)
store i8* %17, i8** %4
%18 = load i8*, i8** %3
%19 = load i8*, i8** %4
%20 = call i32 @sscanf(i8* %18, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = icmp ne i32 %20, 1
br i1 %21, label %22, label %25
22: ; preds = %13
%23 = load i8*, i8** %4
%24 = call i32 @free(i8* %23)
store i8* null, i8** %2
br label %27
25: ; preds = %13
%26 = load i8*, i8** %4
store i8* %26, i8** %2
br label %27
27: ; preds = %25, %22, %12
%28 = load i8*, i8** %2
ret i8* %28
}

LLVM IR (-O2):
@.str = [7 x i8] c"%6[^|]\00"
define i8* @clean_month(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %14, label %3
3: ; preds = %1
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %14, label %6
6: ; preds = %3
%7 = tail call i64 @strlen(i8* %0)
%8 = add nsw i64 %7, 1
%9 = tail call i8* @xmalloc(i64 %8)
%10 = tail call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = icmp eq i32 %10, 1
br i1 %11, label %14, label %12
12: ; preds = %6
%13 = tail call i32 @free(i8* %9)
br label %14
14: ; preds = %12, %6, %1, %3
%15 = phi i8* [ null, %3 ], [ null, %1 ], [ null, %12 ], [ %9, %6 ]
ret i8* %15
}