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

/* Variables and functions */
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int system(char *);
void clapt_lock_apt(char *prog) {
  FILE *lf;
  int sc;
  char rm_cmd[32];
  printf("%s: Locking apt list directory...\n", prog);
  if ((lf = fopen("/var/lib/apt/lists/lock", "r")) != NULL) {
    strcpy(rm_cmd, "sleep 1 && rm -f ");
    strcat(rm_cmd, "/var/lib/apt/lists/lock");
    if ((sc = system(rm_cmd)) == 0)
      printf("Done\n");
    else
      printf("%s: %s", prog, "Command failed to execute due to error(s).");
  }
  putchar('\n');
}


x86 assembly (clang, -O0):
<clapt_lock_apt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe9e(%rip),%rdi
lea    0xeaf(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     1205 <clapt_lock_apt+0xa5>
lea    -0x40(%rbp),%rdi
lea    0xe93(%rip),%rsi
call   1040 <strcpy@plt>
lea    -0x40(%rbp),%rdi
lea    0xe69(%rip),%rsi
call   1080 <strcat@plt>
lea    -0x40(%rbp),%rdi
call   1050 <system@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jne    11e7 <clapt_lock_apt+0x87>
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1200 <clapt_lock_apt+0xa0>
mov    -0x8(%rbp),%rsi
lea    0xe63(%rip),%rdi
lea    0xe63(%rip),%rdx
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1205 <clapt_lock_apt+0xa5>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clapt_lock_apt>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%r14
lea    0xe7f(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe91(%rip),%rdi
lea    0xea2(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11f6 <clapt_lock_apt+0x86>
lea    0xe93(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1040 <strcpy@plt>
lea    0xe67(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strcat@plt>
mov    %rbx,%rdi
call   1060 <system@plt>
test   %eax,%eax
je     11ea <clapt_lock_apt+0x7a>
lea    0xe78(%rip),%rdi
lea    0xe78(%rip),%rdx
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    11f6 <clapt_lock_apt+0x86>
lea    0xe90(%rip),%rdi
call   1050 <puts@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [35 x i8] c"%s: Locking apt list directory...\0A\00"
@.str.1 = [24 x i8] c"/var/lib/apt/lists/lock\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [18 x i8] c"sleep 1 && rm -f \00"
@.str.4 = [6 x i8] c"Done\0A\00"
@.str.5 = [7 x i8] c"%s: %s\00"
@.str.6 = [43 x i8] c"Command failed to execute due to error(s).\00"
define void @clapt_lock_apt(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca [32 x i8]
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = call i32* @fopen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %8, i32** %3
%9 = icmp ne i32* %8, null
br i1 %9, label %10, label %24
10: ; preds = %1
%11 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%12 = call i32 @strcpy(i8* %11, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%13 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%14 = call i32 @strcat(i8* %13, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%15 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%16 = call i32 @system(i8* %15)
store i32 %16, i32* %4
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %10
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
br label %23
20: ; preds = %10
%21 = load i8*, i8** %2
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* %21, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0))
br label %23
23: ; preds = %20, %18
br label %24
24: ; preds = %23, %1
%25 = call i32 @putchar(i8 signext 10)
ret void
}

LLVM IR (-O2):
@.str = [35 x i8] c"%s: Locking apt list directory...\0A\00"
@.str.1 = [24 x i8] c"/var/lib/apt/lists/lock\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [18 x i8] c"sleep 1 && rm -f \00"
@.str.5 = [7 x i8] c"%s: %s\00"
@.str.6 = [43 x i8] c"Command failed to execute due to error(s).\00"
@str = [5 x i8] c"Done\00"
define void @clapt_lock_apt(i8* %0) {
%2 = alloca [32 x i8]
%3 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %0)
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %16, label %7
7: ; preds = %1
%8 = call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%9 = call i32 @strcat(i8* %3, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @system(i8* %3)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
br label %16
14: ; preds = %7
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0))
br label %16
16: ; preds = %12, %14, %1
%17 = call i32 @putchar(i8 signext 10)
ret void
}