#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 /*<<< orphan*/ msg_format;

/* Variables and functions */
int /*<<< orphan*/ LOG_INFO;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char const *, char const *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ printf(char *);
int snprintf(char *, size_t, char const *, char const *);
int /*<<< orphan*/ stderr;
int strlen(char const *);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *);
void incorrect_password(const char *user) {
  int ret;
  static const char msg_format[] = "%s cannot be authenticated.\n";
  size_t len = strlen(user) + sizeof(msg_format);
  char *msg = (char *)malloc(len);
  if (msg == NULL) {
    printf("Could not allocate memory\n");
    exit(0);
  }
  ret = snprintf(msg, len, msg_format, user);
  if (ret < 0) {
    printf("Snprintf did not return successfully\n");
  } else if (ret >= len) {
    printf("Snprintf truncated the message\n");
  }
  fprintf(stderr, msg_format, user);
  syslog(LOG_INFO, msg);
  free(msg);
}


x86 assembly (clang, -O0):
<incorrect_password>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
cltq
add    $0x1d,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ca <incorrect_password+0x4a>
lea    0xe5f(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x8(%rbp),%rcx
lea    0xe23(%rip),%rdx
call   1060 <snprintf@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1200 <incorrect_password+0x80>
lea    0xe42(%rip),%rdi
call   1050 <printf@plt>
jmp    121f <incorrect_password+0x9f>
movslq -0xc(%rbp),%rax
cmp    -0x18(%rbp),%rax
jb     121a <incorrect_password+0x9a>
lea    0xe49(%rip),%rdi
call   1050 <printf@plt>
jmp    121f <incorrect_password+0x9f>
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xdcd(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2d99(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rsi
call   1090 <syslog@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<incorrect_password>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1050 <strlen@plt>
movslq %eax,%rbx
add    $0x1d,%rbx
mov    %rbx,%rdi
call   1080 <malloc@plt>
test   %rax,%rax
je     120f <incorrect_password+0x8f>
mov    %rax,%r15
lea    0xe55(%rip),%rdx
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r14,%rcx
call   1060 <snprintf@plt>
test   %eax,%eax
js     11cd <incorrect_password+0x4d>
mov    %eax,%eax
cmp    %rax,%rbx
ja     11d9 <incorrect_password+0x59>
lea    0xe52(%rip),%rdi
jmp    11d4 <incorrect_password+0x54>
lea    0xe68(%rip),%rdi
call   1040 <puts@plt>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
lea    0xe17(%rip),%rsi
mov    %r14,%rdx
call   1070 <fprintf@plt>
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
mov    %r15,%rsi
call   1090 <syslog@plt>
mov    %r15,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <free@plt>
lea    0xe4b(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@incorrect_password.msg_format = internal constant [29 x i8] c"%s cannot be authenticated.\0A\00"
@.str = [27 x i8] c"Could not allocate memory\0A\00"
@.str.1 = [38 x i8] c"Snprintf did not return successfully\0A\00"
@.str.2 = [32 x i8] c"Snprintf truncated the message\0A\00"
@stderr = global i32 0
@LOG_INFO = global i32 0
define void @incorrect_password(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i64
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @strlen(i8* %6)
%8 = sext i32 %7 to i64
%9 = add i64 %8, 29
store i64 %9, i64* %4
%10 = load i64, i64* %4
%11 = call i64 @malloc(i64 %10)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %5
%13 = load i8*, i8** %5
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %18
15: ; preds = %1
%16 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 0)
unreachable
18: ; preds = %1
%19 = load i8*, i8** %5
%20 = load i64, i64* %4
%21 = load i8*, i8** %2
%22 = call i32 @snprintf(i8* %19, i64 %20, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @incorrect_password.msg_format, i64 0, i64 0), i8* %21)
store i32 %22, i32* %3
%23 = load i32, i32* %3
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %18
%26 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
br label %35
27: ; preds = %18
%28 = load i32, i32* %3
%29 = sext i32 %28 to i64
%30 = load i64, i64* %4
%31 = icmp uge i64 %29, %30
br i1 %31, label %32, label %34
32: ; preds = %27
%33 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
br label %34
34: ; preds = %32, %27
br label %35
35: ; preds = %34, %25
%36 = load i32, i32* @stderr
%37 = load i8*, i8** %2
%38 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @incorrect_password.msg_format, i64 0, i64 0), i8* %37)
%39 = load i32, i32* @LOG_INFO
%40 = load i8*, i8** %5
%41 = call i32 @syslog(i32 %39, i8* %40)
%42 = load i8*, i8** %5
%43 = call i32 @free(i8* %42)
ret void
}

LLVM IR (-O2):
@incorrect_password.msg_format = internal constant [29 x i8] c"%s cannot be authenticated.\0A\00"
@stderr = global i32 0
@LOG_INFO = global i32 0
@str = [31 x i8] c"Snprintf truncated the message\00"
@str.3 = [37 x i8] c"Snprintf did not return successfully\00"
@str.4 = [26 x i8] c"Could not allocate memory\00"
define void @incorrect_password(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = sext i32 %2 to i64
%4 = add nsw i64 %3, 29
%5 = tail call i64 @malloc(i64 %4)
%6 = inttoptr i64 %5 to i8*
%7 = icmp eq i64 %5, 0
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.4, i64 0, i64 0))
%10 = tail call i32 @exit(i32 0)
unreachable
11: ; preds = %1
%12 = tail call i32 @snprintf(i8* %6, i64 %4, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @incorrect_password.msg_format, i64 0, i64 0), i8* %0)
%13 = icmp slt i32 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = zext i32 %12 to i64
%16 = icmp ugt i64 %4, %15
br i1 %16, label %20, label %17
17: ; preds = %14, %11
%18 = phi i8* [ getelementptr inbounds ([37 x i8], [37 x i8]* @str.3, i64 0, i64 0), %11 ], [ getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0), %14 ]
%19 = tail call i32 @puts(i8* dereferenceable(1) %18)
br label %20
20: ; preds = %17, %14
%21 = load i32, i32* @stderr
%22 = tail call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @incorrect_password.msg_format, i64 0, i64 0), i8* %0)
%23 = load i32, i32* @LOG_INFO
%24 = tail call i32 @syslog(i32 %23, i8* %6)
%25 = tail call i32 @free(i8* %6)
ret void
}