#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 */
struct entry {
  int dummy;
};

/* Variables and functions */
struct entry *add_entries(char *, char *, struct entry *);
int /*<<< orphan*/ free(char *);
char *get_username();
char *slurp_command(char *);
char *slurp_file(char *);
struct entry *read_crontabs(int user, int system) {
  struct entry *list = NULL;
  if (user) {
    char *buf = slurp_command("crontab -l");
    if (buf) {
      char *username = get_username();
      list = add_entries(buf, username, list);
      free(username);
      free(buf);
    }
  }
  if (system) {
    char *buf = slurp_file("/etc/crontab");
    if (buf) {
      list = add_entries(buf, NULL, list);
      free(buf);
    }
  }
  return list;
}


x86 assembly (clang, -O0):
<read_crontabs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     11c2 <read_crontabs+0x72>
lea    0xe89(%rip),%rdi
call   1050 <slurp_command@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11bd <read_crontabs+0x6d>
mov    $0x0,%al
call   1040 <get_username@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1060 <add_entries@plt>
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
jmp    11c2 <read_crontabs+0x72>
cmpl   $0x0,-0x8(%rbp)
je     120a <read_crontabs+0xba>
lea    0xe38(%rip),%rdi
call   1070 <slurp_file@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1205 <read_crontabs+0xb5>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%esi
call   1060 <add_entries@plt>
mov    %rax,-0x10(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
jmp    120a <read_crontabs+0xba>
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_crontabs>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
test   %edi,%edi
je     11a3 <read_crontabs+0x53>
lea    0xe9b(%rip),%rdi
call   1050 <slurp_command@plt>
test   %rax,%rax
je     11a3 <read_crontabs+0x53>
mov    %rax,%rbp
xor    %eax,%eax
call   1040 <get_username@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
mov    %rax,%rsi
xor    %edx,%edx
call   1060 <add_entries@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
test   %r14d,%r14d
jne    11ab <read_crontabs+0x5b>
jmp    11dc <read_crontabs+0x8c>
xor    %r15d,%r15d
test   %r14d,%r14d
je     11dc <read_crontabs+0x8c>
lea    0xe59(%rip),%rdi
call   1070 <slurp_file@plt>
test   %rax,%rax
je     11dc <read_crontabs+0x8c>
mov    %rax,%rbp
mov    %rax,%rdi
xor    %esi,%esi
mov    %r15,%rdx
call   1060 <add_entries@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
jmp    11df <read_crontabs+0x8f>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.entry = type { i32 }
@.str = [11 x i8] c"crontab -l\00"
@.str.1 = [13 x i8] c"/etc/crontab\00"
define %struct.entry* @read_crontabs(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.entry*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i32 %0, i32* %3
store i32 %1, i32* %4
store %struct.entry* null, %struct.entry** %5
%9 = load i32, i32* %3
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %26
11: ; preds = %2
%12 = call i8* @slurp_command(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i8* %12, i8** %6
%13 = load i8*, i8** %6
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %25
15: ; preds = %11
%16 = call i8* (...) @get_username()
store i8* %16, i8** %7
%17 = load i8*, i8** %6
%18 = load i8*, i8** %7
%19 = load %struct.entry*, %struct.entry** %5
%20 = call %struct.entry* @add_entries(i8* %17, i8* %18, %struct.entry* %19)
store %struct.entry* %20, %struct.entry** %5
%21 = load i8*, i8** %7
%22 = call i32 @free(i8* %21)
%23 = load i8*, i8** %6
%24 = call i32 @free(i8* %23)
br label %25
25: ; preds = %15, %11
br label %26
26: ; preds = %25, %2
%27 = load i32, i32* %4
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %40
29: ; preds = %26
%30 = call i8* @slurp_file(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
store i8* %30, i8** %8
%31 = load i8*, i8** %8
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %39
33: ; preds = %29
%34 = load i8*, i8** %8
%35 = load %struct.entry*, %struct.entry** %5
%36 = call %struct.entry* @add_entries(i8* %34, i8* null, %struct.entry* %35)
store %struct.entry* %36, %struct.entry** %5
%37 = load i8*, i8** %8
%38 = call i32 @free(i8* %37)
br label %39
39: ; preds = %33, %29
br label %40
40: ; preds = %39, %26
%41 = load %struct.entry*, %struct.entry** %5
ret %struct.entry* %41
}

LLVM IR (-O2):
%struct.entry = type { i32 }
@.str = [11 x i8] c"crontab -l\00"
@.str.1 = [13 x i8] c"/etc/crontab\00"
define %struct.entry* @read_crontabs(i32 %0, i32 %1) {
%3 = icmp eq i32 %0, 0
br i1 %3, label %12, label %4
4: ; preds = %2
%5 = tail call i8* @slurp_command(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %12, label %7
7: ; preds = %4
%8 = tail call i8* (...) @get_username()
%9 = tail call %struct.entry* @add_entries(i8* %5, i8* %8, %struct.entry* null)
%10 = tail call i32 @free(i8* %8)
%11 = tail call i32 @free(i8* %5)
br label %12
12: ; preds = %4, %7, %2
%13 = phi %struct.entry* [ null, %2 ], [ %9, %7 ], [ null, %4 ]
%14 = icmp eq i32 %1, 0
br i1 %14, label %21, label %15
15: ; preds = %12
%16 = tail call i8* @slurp_file(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i8* %16, null
br i1 %17, label %21, label %18
18: ; preds = %15
%19 = tail call %struct.entry* @add_entries(i8* %16, i8* null, %struct.entry* %13)
%20 = tail call i32 @free(i8* %16)
br label %21
21: ; preds = %15, %18, %12
%22 = phi %struct.entry* [ %13, %12 ], [ %19, %18 ], [ %13, %15 ]
ret %struct.entry* %22
}