#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*/ emitconv(int /*<<< orphan*/ *);
int /*<<< orphan*/ emitdev(int /*<<< orphan*/ *);
int /*<<< orphan*/ emitdevm(int /*<<< orphan*/ *);
int /*<<< orphan*/ emitheader(int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ moveifchanged(char *, char *);
int /*<<< orphan*/ warn(char *);
int mkdevsw(void) {
  FILE *fp;
  if ((fp = fopen("devsw.c.tmp", "w")) == NULL) {
    warn("cannot create devsw.c");
    return (1);
  }
  emitheader(fp);
  emitdevm(fp);
  emitconv(fp);
  emitdev(fp);
  fflush(fp);
  if (ferror(fp)) {
    warn("error writing devsw.c");
    fclose(fp);
    return 1;
  }
  (void)fclose(fp);
  if (moveifchanged("devsw.c.tmp", "devsw.c") != 0) {
    warn("error renaming devsw.c");
    return (1);
  }
  return (0);
}


x86 assembly (clang, -O0):
<mkdevsw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xe51(%rip),%rdi
lea    0xe56(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11e1 <mkdevsw+0x41>
lea    0xe3e(%rip),%rdi
call   1030 <warn@plt>
movl   $0x1,-0x4(%rbp)
jmp    1287 <mkdevsw+0xe7>
mov    -0x10(%rbp),%rdi
call   1090 <emitheader@plt>
mov    -0x10(%rbp),%rdi
call   1080 <emitdevm@plt>
mov    -0x10(%rbp),%rdi
call   1060 <emitconv@plt>
mov    -0x10(%rbp),%rdi
call   10b0 <emitdev@plt>
mov    -0x10(%rbp),%rdi
call   1070 <fflush@plt>
mov    -0x10(%rbp),%rdi
call   1040 <ferror@plt>
cmp    $0x0,%rax
je     1242 <mkdevsw+0xa2>
lea    0xdfc(%rip),%rdi
call   1030 <warn@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    1287 <mkdevsw+0xe7>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
lea    0xdae(%rip),%rdi
lea    0xdc3(%rip),%rsi
call   10a0 <moveifchanged@plt>
cmp    $0x0,%rax
je     1280 <mkdevsw+0xe0>
lea    0xdcb(%rip),%rdi
call   1030 <warn@plt>
movl   $0x1,-0x4(%rbp)
jmp    1287 <mkdevsw+0xe7>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mkdevsw>:
push   %rbx
lea    0xe58(%rip),%rdi
lea    0xe5d(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     1207 <mkdevsw+0x67>
mov    %rax,%rbx
mov    %rax,%rdi
call   1090 <emitheader@plt>
mov    %rbx,%rdi
call   1080 <emitdevm@plt>
mov    %rbx,%rdi
call   1060 <emitconv@plt>
mov    %rbx,%rdi
call   10b0 <emitdev@plt>
mov    %rbx,%rdi
call   1070 <fflush@plt>
mov    %rbx,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
je     1210 <mkdevsw+0x70>
lea    0xe2c(%rip),%rdi
call   1030 <warn@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
jmp    123c <mkdevsw+0x9c>
lea    0xe00(%rip),%rdi
jmp    1237 <mkdevsw+0x97>
mov    %rbx,%rdi
call   1050 <fclose@plt>
lea    0xde1(%rip),%rdi
lea    0xdf6(%rip),%rsi
call   10a0 <moveifchanged@plt>
test   %rax,%rax
je     1243 <mkdevsw+0xa3>
lea    0xe03(%rip),%rdi
call   1030 <warn@plt>
mov    $0x1,%eax
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [12 x i8] c"devsw.c.tmp\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [22 x i8] c"cannot create devsw.c\00"
@.str.3 = [22 x i8] c"error writing devsw.c\00"
@.str.4 = [8 x i8] c"devsw.c\00"
@.str.5 = [23 x i8] c"error renaming devsw.c\00"
define i32 @mkdevsw() {
%1 = alloca i32
%2 = alloca i32*
%3 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %3, i32** %2
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = call i32 @warn(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %33
7: ; preds = %0
%8 = load i32*, i32** %2
%9 = call i32 @emitheader(i32* %8)
%10 = load i32*, i32** %2
%11 = call i32 @emitdevm(i32* %10)
%12 = load i32*, i32** %2
%13 = call i32 @emitconv(i32* %12)
%14 = load i32*, i32** %2
%15 = call i32 @emitdev(i32* %14)
%16 = load i32*, i32** %2
%17 = call i32 @fflush(i32* %16)
%18 = load i32*, i32** %2
%19 = call i64 @ferror(i32* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %7
%22 = call i32 @warn(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%23 = load i32*, i32** %2
%24 = call i32 @fclose(i32* %23)
store i32 1, i32* %1
br label %33
25: ; preds = %7
%26 = load i32*, i32** %2
%27 = call i32 @fclose(i32* %26)
%28 = call i64 @moveifchanged(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %25
%31 = call i32 @warn(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %1
br label %33
32: ; preds = %25
store i32 0, i32* %1
br label %33
33: ; preds = %32, %30, %21, %5
%34 = load i32, i32* %1
ret i32 %34
}

LLVM IR (-O2):
@.str = [12 x i8] c"devsw.c.tmp\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [22 x i8] c"cannot create devsw.c\00"
@.str.3 = [22 x i8] c"error writing devsw.c\00"
@.str.4 = [8 x i8] c"devsw.c\00"
@.str.5 = [23 x i8] c"error renaming devsw.c\00"
define i32 @mkdevsw() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @warn(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
br label %22
5: ; preds = %0
%6 = tail call i32 @emitheader(i32* %1)
%7 = tail call i32 @emitdevm(i32* %1)
%8 = tail call i32 @emitconv(i32* %1)
%9 = tail call i32 @emitdev(i32* %1)
%10 = tail call i32 @fflush(i32* %1)
%11 = tail call i64 @ferror(i32* %1)
%12 = icmp eq i64 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %5
%14 = tail call i32 @warn(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%15 = tail call i32 @fclose(i32* %1)
br label %22
16: ; preds = %5
%17 = tail call i32 @fclose(i32* %1)
%18 = tail call i64 @moveifchanged(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %16
%21 = tail call i32 @warn(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
br label %22
22: ; preds = %16, %20, %13, %3
%23 = phi i32 [ 1, %3 ], [ 1, %13 ], [ 1, %20 ], [ 0, %16 ]
ret i32 %23
}