#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*/ error(int, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char const *);
int /*<<< orphan*/ mkd(char *);
int /*<<< orphan*/ printf(char *, ...);
void init(const char *basedir, const char *exclude) {
  FILE *fd;
  printf("[init %s", basedir);
  if (exclude)
    printf(" (%s)", exclude);
  printf("]\n");
  mkd("dbt"
      "/");
  mkd("dbh"
      "/");
  if (!(fd = fopen("basedir", "w")))
    error(1, "basedir open failed");
  fprintf(fd, "%s\n", basedir);
  fclose(fd);
  if (!exclude)
    return;
  if (!(fd = fopen("exclude", "w")))
    error(1, "exclude open failed");
  fprintf(fd, "%s\n", exclude);
  fclose(fd);
}


x86 assembly (clang, -O0):
<init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpq   $0x0,-0x10(%rbp)
je     119f <init+0x3f>
mov    -0x10(%rbp),%rsi
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe5e(%rip),%rdi
call   1060 <mkd@plt>
lea    0xe57(%rip),%rdi
call   1060 <mkd@plt>
lea    0xe50(%rip),%rdi
lea    0xe51(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11f7 <init+0x97>
mov    $0x1,%edi
lea    0xe34(%rip),%rsi
call   1070 <error@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe34(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
cmpq   $0x0,-0x10(%rbp)
jne    1224 <init+0xc4>
jmp    1273 <init+0x113>
lea    0xe13(%rip),%rdi
lea    0xdf2(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1256 <init+0xf6>
mov    $0x1,%edi
lea    0xdf5(%rip),%rsi
call   1070 <error@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xdd5(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe7e(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
test   %r14,%r14
je     11a2 <init+0x32>
lea    0xe71(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeae(%rip),%rdi
call   1030 <puts@plt>
lea    0xe5a(%rip),%rdi
call   1070 <mkd@plt>
lea    0xe53(%rip),%rdi
call   1070 <mkd@plt>
lea    0xe4c(%rip),%rdi
lea    0xe4d(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11f2 <init+0x82>
lea    0xe3b(%rip),%rsi
mov    $0x1,%edi
call   1080 <error@plt>
lea    0xe3e(%rip),%rsi
mov    %rbx,%rdi
mov    %r15,%rdx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
test   %r14,%r14
je     125c <init+0xec>
lea    0xe23(%rip),%rdi
lea    0xe02(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    123d <init+0xcd>
lea    0xe10(%rip),%rsi
mov    $0x1,%edi
call   1080 <error@plt>
lea    0xdf3(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <fclose@plt>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [9 x i8] c"[init %s\00"
@.str.1 = [6 x i8] c" (%s)\00"
@.str.2 = [3 x i8] c"]\0A\00"
@.str.3 = [5 x i8] c"dbt/\00"
@.str.4 = [5 x i8] c"dbh/\00"
@.str.5 = [8 x i8] c"basedir\00"
@.str.6 = [2 x i8] c"w\00"
@.str.7 = [20 x i8] c"basedir open failed\00"
@.str.8 = [4 x i8] c"%s\0A\00"
@.str.9 = [8 x i8] c"exclude\00"
@.str.10 = [20 x i8] c"exclude open failed\00"
define void @init(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %3
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = load i8*, i8** %4
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %11)
br label %13
13: ; preds = %10, %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 @mkd(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%16 = call i32 @mkd(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%17 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %17, i32** %5
%18 = icmp ne i32* %17, null
br i1 %18, label %21, label %19
19: ; preds = %13
%20 = call i32 @error(i32 1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0))
br label %21
21: ; preds = %19, %13
%22 = load i32*, i32** %5
%23 = load i8*, i8** %3
%24 = call i32 @fprintf(i32* %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* %23)
%25 = load i32*, i32** %5
%26 = call i32 @fclose(i32* %25)
%27 = load i8*, i8** %4
%28 = icmp ne i8* %27, null
br i1 %28, label %30, label %29
29: ; preds = %21
br label %41
30: ; preds = %21
%31 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %31, i32** %5
%32 = icmp ne i32* %31, null
br i1 %32, label %35, label %33
33: ; preds = %30
%34 = call i32 @error(i32 1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.10, i64 0, i64 0))
br label %35
35: ; preds = %33, %30
%36 = load i32*, i32** %5
%37 = load i8*, i8** %4
%38 = call i32 @fprintf(i32* %36, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* %37)
%39 = load i32*, i32** %5
%40 = call i32 @fclose(i32* %39)
br label %41
41: ; preds = %35, %29
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"[init %s\00"
@.str.1 = [6 x i8] c" (%s)\00"
@.str.3 = [5 x i8] c"dbt/\00"
@.str.4 = [5 x i8] c"dbh/\00"
@.str.5 = [8 x i8] c"basedir\00"
@.str.6 = [2 x i8] c"w\00"
@.str.7 = [20 x i8] c"basedir open failed\00"
@.str.8 = [4 x i8] c"%s\0A\00"
@.str.9 = [8 x i8] c"exclude\00"
@.str.10 = [20 x i8] c"exclude open failed\00"
@str = [2 x i8] c"]\00"
define void @init(i8* %0, i8* %1) {
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %0)
%4 = icmp eq i8* %1, null
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %1)
br label %7
7: ; preds = %5, %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
%9 = tail call i32 @mkd(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%10 = tail call i32 @mkd(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%11 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %7
%14 = tail call i32 @error(i32 1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0))
br label %15
15: ; preds = %13, %7
%16 = tail call i32 @fprintf(i32* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* %0)
%17 = tail call i32 @fclose(i32* %11)
br i1 %4, label %26, label %18
18: ; preds = %15
%19 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = tail call i32 @error(i32 1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.10, i64 0, i64 0))
br label %23
23: ; preds = %21, %18
%24 = tail call i32 @fprintf(i32* %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* %1)
%25 = tail call i32 @fclose(i32* %19)
br label %26
26: ; preds = %15, %23
ret void
}