#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*/ EXIT_SUCCESS;
int /*<<< orphan*/ abort();
int /*<<< orphan*/ err(int /*<<< orphan*/, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
scalar_t__ mlock(char *, int);
int main(int argc, char **argv) {
  char *password = (char *)malloc(sizeof("password"));
  if (!password) {
    err(EXIT_SUCCESS, "malloc");
  }
  memcpy(password, "password", sizeof("password"));
  if (mlock(password, sizeof("password"))) {
    err(EXIT_SUCCESS, "mlock");
  }
  abort();
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x9,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1194 <main+0x44>
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
lea    0xe71(%rip),%rsi
call   1060 <err@plt>
mov    -0x18(%rbp),%rdi
lea    0xe68(%rip),%rsi
mov    $0x9,%edx
call   1050 <memcpy@plt>
mov    -0x18(%rbp),%rdi
mov    $0x9,%esi
call   1040 <mlock@plt>
cmp    $0x0,%rax
je     11d6 <main+0x86>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
lea    0xe3f(%rip),%rsi
call   1060 <err@plt>
mov    $0x0,%al
call   1030 <abort@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x9,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1178 <main+0x28>
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
lea    0xe8d(%rip),%rsi
call   1060 <err@plt>
lea    0xe88(%rip),%rsi
mov    %rbx,%rdi
mov    $0x9,%edx
call   1050 <memcpy@plt>
mov    %rbx,%rdi
mov    $0x9,%esi
call   1040 <mlock@plt>
test   %rax,%rax
je     11b3 <main+0x63>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
lea    0xe62(%rip),%rsi
call   1060 <err@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@EXIT_SUCCESS = global i32 0
@.str = [7 x i8] c"malloc\00"
@.str.1 = [9 x i8] c"password\00"
@.str.2 = [6 x i8] c"mlock\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i64 @malloc(i32 9)
%8 = inttoptr i64 %7 to i8*
store i8* %8, i8** %6
%9 = load i8*, i8** %6
%10 = icmp ne i8* %9, null
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = load i32, i32* @EXIT_SUCCESS
%13 = call i32 @err(i32 %12, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %11, %2
%15 = load i8*, i8** %6
%16 = call i32 @memcpy(i8* %15, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 9)
%17 = load i8*, i8** %6
%18 = call i64 @mlock(i8* %17, i32 9)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %14
%21 = load i32, i32* @EXIT_SUCCESS
%22 = call i32 @err(i32 %21, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %23
23: ; preds = %20, %14
%24 = call i32 (...) @abort()
unreachable
}

LLVM IR (-O2):
@EXIT_SUCCESS = global i32 0
@.str = [7 x i8] c"malloc\00"
@.str.1 = [9 x i8] c"password\00"
@.str.2 = [6 x i8] c"mlock\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 @malloc(i32 9)
%4 = inttoptr i64 %3 to i8*
%5 = icmp eq i64 %3, 0
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i32, i32* @EXIT_SUCCESS
%8 = tail call i32 @err(i32 %7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %6, %2
%10 = tail call i32 @memcpy(i8* %4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 9)
%11 = tail call i64 @mlock(i8* %4, i32 9)
%12 = icmp eq i64 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %9
%14 = load i32, i32* @EXIT_SUCCESS
%15 = tail call i32 @err(i32 %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %16
16: ; preds = %13, %9
%17 = tail call i32 (...) @abort()
unreachable
}