#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 tuple_list {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dumpcis(struct tuple_list *);
int /*<<< orphan*/ freecis(struct tuple_list *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
struct tuple_list *readcis(int);
void scanfile(char *name) {
  int fd;
  struct tuple_list *tl;
  fd = open(name, O_RDONLY);
  if (fd < 0)
    return;
  tl = readcis(fd);
  if (tl) {
    printf("Configuration data for file %s\n", name);
    dumpcis(tl);
    freecis(tl);
  }
  close(fd);
}


x86 assembly (clang, -O0):
<scanfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e71(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1190 <scanfile+0x30>
jmp    11d1 <scanfile+0x71>
mov    -0xc(%rbp),%edi
call   1060 <readcis@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11c9 <scanfile+0x69>
mov    -0x8(%rbp),%rsi
lea    0xe4e(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1080 <dumpcis@plt>
mov    -0x18(%rbp),%rdi
call   1050 <freecis@plt>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scanfile>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    0x2e79(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
test   %eax,%eax
js     11b6 <scanfile+0x56>
mov    %eax,%ebx
mov    %eax,%edi
call   1060 <readcis@plt>
test   %rax,%rax
je     11aa <scanfile+0x4a>
mov    %rax,%r15
lea    0xe6e(%rip),%rdi
mov    %r14,%rsi
call   1030 <printf@plt>
mov    %r15,%rdi
call   1080 <dumpcis@plt>
mov    %r15,%rdi
call   1050 <freecis@plt>
mov    %ebx,%edi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <close@plt>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.tuple_list = type { i32 }
@O_RDONLY = global i32 0
@.str = [32 x i8] c"Configuration data for file %s\0A\00"
define void @scanfile(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca %struct.tuple_list*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = load i32, i32* @O_RDONLY
%7 = call i32 @open(i8* %5, i32 %6)
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %1
br label %26
11: ; preds = %1
%12 = load i32, i32* %3
%13 = call %struct.tuple_list* @readcis(i32 %12)
store %struct.tuple_list* %13, %struct.tuple_list** %4
%14 = load %struct.tuple_list*, %struct.tuple_list** %4
%15 = icmp ne %struct.tuple_list* %14, null
br i1 %15, label %16, label %23
16: ; preds = %11
%17 = load i8*, i8** %2
%18 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = load %struct.tuple_list*, %struct.tuple_list** %4
%20 = call i32 @dumpcis(%struct.tuple_list* %19)
%21 = load %struct.tuple_list*, %struct.tuple_list** %4
%22 = call i32 @freecis(%struct.tuple_list* %21)
br label %23
23: ; preds = %16, %11
%24 = load i32, i32* %3
%25 = call i32 @close(i32 %24)
br label %26
26: ; preds = %23, %10
ret void
}

LLVM IR (-O2):
%struct.tuple_list = type { i32 }
@O_RDONLY = global i32 0
@.str = [32 x i8] c"Configuration data for file %s\0A\00"
define void @scanfile(i8* %0) {
%2 = load i32, i32* @O_RDONLY
%3 = tail call i32 @open(i8* %0, i32 %2)
%4 = icmp slt i32 %3, 0
br i1 %4, label %14, label %5
5: ; preds = %1
%6 = tail call %struct.tuple_list* @readcis(i32 %3)
%7 = icmp eq %struct.tuple_list* %6, null
br i1 %7, label %12, label %8
8: ; preds = %5
%9 = tail call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %0)
%10 = tail call i32 @dumpcis(%struct.tuple_list* %6)
%11 = tail call i32 @freecis(%struct.tuple_list* %6)
br label %12
12: ; preds = %8, %5
%13 = tail call i32 @close(i32 %3)
br label %14
14: ; preds = %1, %12
ret void
}