#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_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
char *calloc(int, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, int);
int main(int argc, char *argv[]) {
  char *pt;
  if (NULL == (pt = calloc(sizeof(*pt), 10))) {
    char *msg = NULL;
    sprintf(msg, "%s %d",
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/jeremiedecock/snippets/refs/heads/"
            "master/c/clean_calloc.c",
            10);
    perror(msg);
    exit(EXIT_FAILURE);
  }
  free(pt);
  exit(EXIT_SUCCESS);
}


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    $0x1,%edi
mov    $0xa,%esi
call   1040 <calloc@plt>
mov    %rax,%rcx
mov    %rcx,-0x18(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    11c2 <main+0x72>
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe66(%rip),%rsi
lea    0xe65(%rip),%rdx
mov    $0xa,%ecx
call   1060 <sprintf@plt>
mov    -0x20(%rbp),%rdi
call   1050 <perror@plt>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    $0x1,%edi
mov    $0xa,%esi
call   1040 <calloc@plt>
test   %rax,%rax
jne    1194 <main+0x44>
lea    0xe94(%rip),%rsi
lea    0xe93(%rip),%rdx
xor    %edi,%edi
mov    $0xa,%ecx
call   1060 <sprintf@plt>
xor    %edi,%edi
call   1050 <perror@plt>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    %rax,%rdi
call   1030 <free@plt>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"%s %d\00"
@.str.1 = [148 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/jeremiedecock/snippets/refs/heads/master/c/clean_calloc.c\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i8* @calloc(i32 1, i32 10)
store i8* %8, i8** %6
%9 = icmp eq i8* null, %8
br i1 %9, label %10, label %17
10: ; preds = %2
store i8* null, i8** %7
%11 = load i8*, i8** %7
%12 = call i32 @sprintf(i8* %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([148 x i8], [148 x i8]* @.str.1, i64 0, i64 0), i32 10)
%13 = load i8*, i8** %7
%14 = call i32 @perror(i8* %13)
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %2
%18 = load i8*, i8** %6
%19 = call i32 @free(i8* %18)
%20 = load i32, i32* @EXIT_SUCCESS
%21 = call i32 @exit(i32 %20)
unreachable
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s %d\00"
@.str.1 = [148 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/jeremiedecock/snippets/refs/heads/master/c/clean_calloc.c\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call dereferenceable_or_null(10) i8* @calloc(i32 1, i32 10)
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %10
5: ; preds = %2
%6 = tail call i32 @sprintf(i8* dereferenceable(1) null, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([148 x i8], [148 x i8]* @.str.1, i64 0, i64 0), i32 10)
%7 = tail call i32 @perror(i8* null)
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %2
%11 = tail call i32 @free(i8* %3)
%12 = load i32, i32* @EXIT_SUCCESS
%13 = tail call i32 @exit(i32 %12)
unreachable
}