#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 */
char *malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, int);
char *do_date(int mday) {
  char *dbuff = malloc(5);
  switch (mday) {
  case 1:
  case 21:
  case 31:
    sprintf(dbuff, "%dst", mday);
    break;
  case 2:
  case 22:
    sprintf(dbuff, "%dnd", mday);
    break;
  case 3:
  case 23:
    sprintf(dbuff, "%drd", mday);
    break;
  default:
    sprintf(dbuff, "%dth", mday);
    break;
  }
  return (dbuff);
}


x86 assembly (clang, -O0):
<do_date>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x5,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x14(%rbp)
sub    $0x1,%eax
je     11b3 <do_date+0x93>
jmp    114d <do_date+0x2d>
mov    -0x14(%rbp),%eax
sub    $0x2,%eax
je     11cb <do_date+0xab>
jmp    115e <do_date+0x3e>
mov    -0x14(%rbp),%eax
sub    $0x3,%eax
je     11e3 <do_date+0xc3>
jmp    116f <do_date+0x4f>
mov    -0x14(%rbp),%eax
sub    $0x15,%eax
je     11b3 <do_date+0x93>
jmp    1180 <do_date+0x60>
mov    -0x14(%rbp),%eax
sub    $0x16,%eax
je     11cb <do_date+0xab>
jmp    1191 <do_date+0x71>
mov    -0x14(%rbp),%eax
sub    $0x17,%eax
je     11e3 <do_date+0xc3>
jmp    11a2 <do_date+0x82>
mov    -0x14(%rbp),%eax
sub    $0x1f,%eax
jne    11fb <do_date+0xdb>
jmp    11b3 <do_date+0x93>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe3f(%rip),%rsi
call   1040 <sprintf@plt>
jmp    120e <do_date+0xee>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe2c(%rip),%rsi
call   1040 <sprintf@plt>
jmp    120e <do_date+0xee>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe19(%rip),%rsi
call   1040 <sprintf@plt>
jmp    120e <do_date+0xee>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe06(%rip),%rsi
call   1040 <sprintf@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_date>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
mov    $0x5,%edi
call   1030 <malloc@plt>
mov    %rax,%r14
cmp    $0x1f,%ebx
ja     1171 <do_date+0x51>
mov    $0x80200002,%eax
bt     %ebx,%eax
jb     115f <do_date+0x3f>
mov    $0x400004,%eax
bt     %ebx,%eax
jb     1168 <do_date+0x48>
mov    $0x800008,%eax
bt     %ebx,%eax
jae    1171 <do_date+0x51>
lea    0xead(%rip),%rsi
jmp    1178 <do_date+0x58>
lea    0xe9a(%rip),%rsi
jmp    1178 <do_date+0x58>
lea    0xe96(%rip),%rsi
jmp    1178 <do_date+0x58>
lea    0xe97(%rip),%rsi
mov    %r14,%rdi
mov    %ebx,%edx
call   1040 <sprintf@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%dst\00"
@.str.1 = [5 x i8] c"%dnd\00"
@.str.2 = [5 x i8] c"%drd\00"
@.str.3 = [5 x i8] c"%dth\00"
define i8* @do_date(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
store i32 %0, i32* %2
%4 = call i8* @malloc(i32 5)
store i8* %4, i8** %3
%5 = load i32, i32* %2
switch i32 %5, label %18 [
i32 1, label %6
i32 21, label %6
i32 31, label %6
i32 2, label %10
i32 22, label %10
i32 3, label %14
i32 23, label %14
]
6: ; preds = %1, %1, %1
%7 = load i8*, i8** %3
%8 = load i32, i32* %2
%9 = call i32 @sprintf(i8* %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %8)
br label %22
10: ; preds = %1, %1
%11 = load i8*, i8** %3
%12 = load i32, i32* %2
%13 = call i32 @sprintf(i8* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %12)
br label %22
14: ; preds = %1, %1
%15 = load i8*, i8** %3
%16 = load i32, i32* %2
%17 = call i32 @sprintf(i8* %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %16)
br label %22
18: ; preds = %1
%19 = load i8*, i8** %3
%20 = load i32, i32* %2
%21 = call i32 @sprintf(i8* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %18, %14, %10, %6
%23 = load i8*, i8** %3
ret i8* %23
}

LLVM IR (-O2):
@.str = [5 x i8] c"%dst\00"
@.str.1 = [5 x i8] c"%dnd\00"
@.str.2 = [5 x i8] c"%drd\00"
@.str.3 = [5 x i8] c"%dth\00"
define noalias i8* @do_date(i32 %0) {
%2 = tail call dereferenceable_or_null(5) i8* @malloc(i32 5)
switch i32 %0, label %5 [
i32 1, label %6
i32 21, label %6
i32 31, label %6
i32 2, label %3
i32 22, label %3
i32 3, label %4
i32 23, label %4
]
3: ; preds = %1, %1
br label %6
4: ; preds = %1, %1
br label %6
5: ; preds = %1
br label %6
6: ; preds = %1, %1, %1, %5, %4, %3
%7 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), %5 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), %4 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %3 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %1 ]
%8 = tail call i32 @sprintf(i8* dereferenceable(1) %2, i8* dereferenceable(1) %7, i32 %0)
ret i8* %2
}