#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 O_CREAT;
int O_WRONLY;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char *);
int open(char *, int, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char *);
char *uppercase_str(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int create_head(char *path) {
  int fd;
  int i;
  char *tmp;
  i = 0;
  while (path[i] != '\0')
    ++i;
  while (i > 0 && path[i] != '/')
    --i;
  if (i > 0)
    ++i;
  if ((fd = open(path, O_WRONLY | O_CREAT,
                 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) <= 0) {
    fprintf(stderr, "Can't create %s\n", path);
    exit(-1);
  }
  tmp = uppercase_str(&path[i]);
  write(fd, "#ifndef ", strlen("#ifndef "));
  write(fd, tmp, strlen(tmp));
  write(fd, "_\n# define ", strlen("_\n# define "));
  write(fd, tmp, strlen(tmp));
  write(fd, "_\n\n\n#endif /* ! ", strlen("_\n\n\n#endif /* ! "));
  write(fd, tmp, strlen(tmp));
  write(fd, "_ */\n", strlen("_ */\n"));
  free(tmp);
  return (fd);
}


x86 assembly (clang, -O0):
<create_head>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11a6 <create_head+0x36>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1183 <create_head+0x13>
jmp    11ab <create_head+0x3b>
xor    %eax,%eax
cmpl   $0x0,-0x10(%rbp)
mov    %al,-0x19(%rbp)
jle    11cf <create_head+0x5f>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11df <create_head+0x6f>
jmp    11ed <create_head+0x7d>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    11ab <create_head+0x3b>
cmpl   $0x0,-0x10(%rbp)
jle    1200 <create_head+0x90>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2d9d(%rip),%rax
mov    (%rax),%esi
mov    0x2de4(%rip),%rax
or     (%rax),%esi
mov    0x2d9b(%rip),%rax
mov    (%rax),%edx
mov    0x2dba(%rip),%rax
or     (%rax),%edx
mov    0x2d99(%rip),%rax
or     (%rax),%edx
mov    0x2d88(%rip),%rax
or     (%rax),%edx
call   1070 <open@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jg     126e <create_head+0xfe>
mov    0x2d7e(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xda1(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%rdi
movslq -0x10(%rbp),%rax
add    %rax,%rdi
call   1090 <uppercase_str@plt>
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x50(%rbp)
lea    0xd82(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x50(%rbp),%edi
mov    %eax,%edx
lea    0xd71(%rip),%rsi
call   1040 <write@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x40(%rbp)
lea    0xd43(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x40(%rbp),%edi
mov    %eax,%edx
lea    0xd32(%rip),%rsi
call   1040 <write@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x30(%rbp)
lea    0xd07(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x30(%rbp),%edi
mov    %eax,%edx
lea    0xcf6(%rip),%rsi
call   1040 <write@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x20(%rbp)
lea    0xcd0(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x20(%rbp),%edi
mov    %eax,%edx
lea    0xcbf(%rip),%rsi
call   1040 <write@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0xc(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_head>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %ebp,%ebp
nopl   0x0(%rax)
cmpb   $0x0,(%rbx,%rbp,1)
lea    0x1(%rbp),%rbp
jne    1180 <create_head+0x10>
xor    %r14d,%r14d
cmp    $0x1,%ebp
jne    1196 <create_head+0x26>
xor    %ebp,%ebp
jmp    11cc <create_head+0x5c>
add    $0xffffffffffffffff,%rbp
test   %ebp,%ebp
mov    $0x1,%ecx
mov    %ebp,%eax
cmovg  %ecx,%eax
add    $0xffffffff,%eax
nopl   0x0(%rax)
mov    %ebp,%ecx
cmpb   $0x2f,(%rbx,%rcx,1)
je     11c6 <create_head+0x56>
lea    -0x1(%rbp),%ecx
cmp    $0x1,%ebp
mov    %ecx,%ebp
jg     11b0 <create_head+0x40>
mov    %eax,%ebp
jmp    11cc <create_head+0x5c>
mov    $0x1,%r14d
mov    0x2dd5(%rip),%rax
mov    0x2e1e(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2dd3(%rip),%rax
mov    0x2df4(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2dd1(%rip),%rax
or     (%rax),%edx
mov    0x2dc0(%rip),%rax
or     (%rax),%edx
mov    %rbx,%rdi
call   1070 <open@plt>
test   %eax,%eax
jle    12ee <create_head+0x17e>
mov    %eax,%r15d
add    %r14d,%ebp
movslq %ebp,%rax
add    %rax,%rbx
mov    %rbx,%rdi
call   1090 <uppercase_str@plt>
mov    %rax,%rbx
lea    0xde1(%rip),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %r15d,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
lea    0xdb9(%rip),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %r15d,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
lea    0xd94(%rip),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %r15d,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
lea    0xd74(%rip),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %r15d,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cdb(%rip),%rax
mov    (%rax),%edi
lea    0xd02(%rip),%rsi
mov    %rbx,%rdx
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@stderr = global i32 0
@.str = [17 x i8] c"Can't create %s\0A\00"
@.str.1 = [9 x i8] c"#ifndef \00"
@.str.2 = [12 x i8] c"_\0A# define \00"
@.str.3 = [17 x i8] c"_\0A\0A\0A#endif /* ! \00"
@.str.4 = [6 x i8] c"_ */\0A\00"
define i32 @create_head(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %2
store i32 0, i32* %4
br label %6
6: ; preds = %14, %1
%7 = load i8*, i8** %2
%8 = load i32, i32* %4
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %7, i64 %9
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %6
%15 = load i32, i32* %4
%16 = add nsw i32 %15, 1
store i32 %16, i32* %4
br label %6
17: ; preds = %6
br label %18
18: ; preds = %31, %17
%19 = load i32, i32* %4
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %29
21: ; preds = %18
%22 = load i8*, i8** %2
%23 = load i32, i32* %4
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 47
br label %29
29: ; preds = %21, %18
%30 = phi i1 [ false, %18 ], [ %28, %21 ]
br i1 %30, label %31, label %34
31: ; preds = %29
%32 = load i32, i32* %4
%33 = add nsw i32 %32, -1
store i32 %33, i32* %4
br label %18
34: ; preds = %29
%35 = load i32, i32* %4
%36 = icmp sgt i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %34
%38 = load i32, i32* %4
%39 = add nsw i32 %38, 1
store i32 %39, i32* %4
br label %40
40: ; preds = %37, %34
%41 = load i8*, i8** %2
%42 = load i32, i32* @O_WRONLY
%43 = load i32, i32* @O_CREAT
%44 = or i32 %42, %43
%45 = load i32, i32* @S_IRUSR
%46 = load i32, i32* @S_IWUSR
%47 = or i32 %45, %46
%48 = load i32, i32* @S_IRGRP
%49 = or i32 %47, %48
%50 = load i32, i32* @S_IROTH
%51 = or i32 %49, %50
%52 = call i32 @open(i8* %41, i32 %44, i32 %51)
store i32 %52, i32* %3
%53 = icmp sle i32 %52, 0
br i1 %53, label %54, label %59
54: ; preds = %40
%55 = load i32, i32* @stderr
%56 = load i8*, i8** %2
%57 = call i32 @fprintf(i32 %55, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %56)
%58 = call i32 @exit(i32 -1)
unreachable
59: ; preds = %40
%60 = load i8*, i8** %2
%61 = load i32, i32* %4
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %60, i64 %62
%64 = call i8* @uppercase_str(i8* %63)
store i8* %64, i8** %5
%65 = load i32, i32* %3
%66 = call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%67 = call i32 @write(i32 %65, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %66)
%68 = load i32, i32* %3
%69 = load i8*, i8** %5
%70 = load i8*, i8** %5
%71 = call i32 @strlen(i8* %70)
%72 = call i32 @write(i32 %68, i8* %69, i32 %71)
%73 = load i32, i32* %3
%74 = call i32 @strlen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%75 = call i32 @write(i32 %73, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %74)
%76 = load i32, i32* %3
%77 = load i8*, i8** %5
%78 = load i8*, i8** %5
%79 = call i32 @strlen(i8* %78)
%80 = call i32 @write(i32 %76, i8* %77, i32 %79)
%81 = load i32, i32* %3
%82 = call i32 @strlen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%83 = call i32 @write(i32 %81, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %82)
%84 = load i32, i32* %3
%85 = load i8*, i8** %5
%86 = load i8*, i8** %5
%87 = call i32 @strlen(i8* %86)
%88 = call i32 @write(i32 %84, i8* %85, i32 %87)
%89 = load i32, i32* %3
%90 = call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%91 = call i32 @write(i32 %89, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %90)
%92 = load i8*, i8** %5
%93 = call i32 @free(i8* %92)
%94 = load i32, i32* %3
ret i32 %94
}

LLVM IR (-O2):
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@stderr = global i32 0
@.str = [17 x i8] c"Can't create %s\0A\00"
@.str.1 = [9 x i8] c"#ifndef \00"
@.str.2 = [12 x i8] c"_\0A# define \00"
@.str.3 = [17 x i8] c"_\0A\0A\0A#endif /* ! \00"
@.str.4 = [6 x i8] c"_ */\0A\00"
define i32 @create_head(i8* %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i64 [ %7, %2 ], [ 0, %1 ]
%4 = getelementptr inbounds i8, i8* %0, i64 %3
%5 = load i8, i8* %4
%6 = icmp eq i8 %5, 0
%7 = add nuw i64 %3, 1
br i1 %6, label %8, label %2
8: ; preds = %2
%9 = trunc i64 %3 to i32
%10 = icmp eq i32 %9, 0
br i1 %10, label %23, label %11
11: ; preds = %8
%12 = call i32 @llvm.smin.i32(i32 %9, i32 1)
%13 = add i32 %12, -1
br label %14
14: ; preds = %11, %20
%15 = phi i32 [ %21, %20 ], [ %9, %11 ]
%16 = zext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %0, i64 %16
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 47
br i1 %19, label %23, label %20
20: ; preds = %14
%21 = add nsw i32 %15, -1
%22 = icmp sgt i32 %15, 1
br i1 %22, label %14, label %23
23: ; preds = %14, %20, %8
%24 = phi i32 [ 0, %8 ], [ %13, %20 ], [ %15, %14 ]
%25 = phi i32 [ 0, %8 ], [ 0, %20 ], [ 1, %14 ]
%26 = load i32, i32* @O_WRONLY
%27 = load i32, i32* @O_CREAT
%28 = or i32 %27, %26
%29 = load i32, i32* @S_IRUSR
%30 = load i32, i32* @S_IWUSR
%31 = or i32 %30, %29
%32 = load i32, i32* @S_IRGRP
%33 = or i32 %31, %32
%34 = load i32, i32* @S_IROTH
%35 = or i32 %33, %34
%36 = tail call i32 @open(i8* %0, i32 %28, i32 %35)
%37 = icmp slt i32 %36, 1
br i1 %37, label %38, label %42
38: ; preds = %23
%39 = load i32, i32* @stderr
%40 = tail call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %0)
%41 = tail call i32 @exit(i32 -1)
unreachable
42: ; preds = %23
%43 = add nsw i32 %24, %25
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %0, i64 %44
%46 = tail call i8* @uppercase_str(i8* %45)
%47 = tail call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%48 = tail call i32 @write(i32 %36, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %47)
%49 = tail call i32 @strlen(i8* %46)
%50 = tail call i32 @write(i32 %36, i8* %46, i32 %49)
%51 = tail call i32 @strlen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%52 = tail call i32 @write(i32 %36, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %51)
%53 = tail call i32 @strlen(i8* %46)
%54 = tail call i32 @write(i32 %36, i8* %46, i32 %53)
%55 = tail call i32 @strlen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%56 = tail call i32 @write(i32 %36, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %55)
%57 = tail call i32 @strlen(i8* %46)
%58 = tail call i32 @write(i32 %36, i8* %46, i32 %57)
%59 = tail call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%60 = tail call i32 @write(i32 %36, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %59)
%61 = tail call i32 @free(i8* %46)
ret i32 %36
}