#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 */
scalar_t__ calloc(int, int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *get_ack_nack(int success) {
  char *ret = NULL;
  if (success == -1) {
    return NULL;
  }
  if (success) {
    ret = (char *)calloc(1, (strlen("ACK") + 1) * sizeof(char));
    strcpy(ret, "ACK");
  } else {
    ret = (char *)calloc(1, (strlen("NACK") + 1) * sizeof(char));
    strcpy(ret, "NACK");
  }
  return ret;
}


x86 assembly (clang, -O0):
<get_ack_nack>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    115a <get_ack_nack+0x2a>
movq   $0x0,-0x8(%rbp)
jmp    11db <get_ack_nack+0xab>
cmpl   $0x0,-0xc(%rbp)
je     119e <get_ack_nack+0x6e>
lea    0xe96(%rip),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%esi
mov    $0x1,%edi
call   1050 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe6d(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11d3 <get_ack_nack+0xa3>
lea    0xe5b(%rip),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%esi
mov    $0x1,%edi
call   1050 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe32(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_ack_nack>:
push   %r14
push   %rbx
push   %rax
cmp    $0xffffffff,%edi
je     1146 <get_ack_nack+0x16>
test   %edi,%edi
jne    114a <get_ack_nack+0x1a>
lea    0xebc(%rip),%r14
jmp    1151 <get_ack_nack+0x21>
xor    %ebx,%ebx
jmp    1174 <get_ack_nack+0x44>
lea    0xeb0(%rip),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%esi
mov    $0x1,%edi
call   1050 <calloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [4 x i8] c"ACK\00"
@.str.1 = [5 x i8] c"NACK\00"
define i8* @get_ack_nack(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %3
store i8* null, i8** %4
%5 = load i32, i32* %3
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %8
7: ; preds = %1
store i8* null, i8** %2
br label %33
8: ; preds = %1
%9 = load i32, i32* %3
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %21
11: ; preds = %8
%12 = call i32 @strlen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%13 = add nsw i32 %12, 1
%14 = sext i32 %13 to i64
%15 = mul i64 %14, 1
%16 = trunc i64 %15 to i32
%17 = call i64 @calloc(i32 1, i32 %16)
%18 = inttoptr i64 %17 to i8*
store i8* %18, i8** %4
%19 = load i8*, i8** %4
%20 = call i32 @strcpy(i8* %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %31
21: ; preds = %8
%22 = call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%23 = add nsw i32 %22, 1
%24 = sext i32 %23 to i64
%25 = mul i64 %24, 1
%26 = trunc i64 %25 to i32
%27 = call i64 @calloc(i32 1, i32 %26)
%28 = inttoptr i64 %27 to i8*
store i8* %28, i8** %4
%29 = load i8*, i8** %4
%30 = call i32 @strcpy(i8* %29, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %31
31: ; preds = %21, %11
%32 = load i8*, i8** %4
store i8* %32, i8** %2
br label %33
33: ; preds = %31, %7
%34 = load i8*, i8** %2
ret i8* %34
}

LLVM IR (-O2):
@.str = [4 x i8] c"ACK\00"
@.str.1 = [5 x i8] c"NACK\00"
define i8* @get_ack_nack(i32 %0) {
switch i32 %0, label %2 [
i32 -1, label %14
i32 0, label %8
]
2: ; preds = %1
%3 = tail call i32 @strlen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%4 = add nsw i32 %3, 1
%5 = tail call i64 @calloc(i32 1, i32 %4)
%6 = inttoptr i64 %5 to i8*
%7 = tail call i32 @strcpy(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %14
8: ; preds = %1
%9 = tail call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%10 = add nsw i32 %9, 1
%11 = tail call i64 @calloc(i32 1, i32 %10)
%12 = inttoptr i64 %11 to i8*
%13 = tail call i32 @strcpy(i8* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %2, %8, %1
%15 = phi i8* [ null, %1 ], [ %6, %2 ], [ %12, %8 ]
ret i8* %15
}