#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 uid_t;
struct stat {
  int /*<<< orphan*/ st_rdev;
  int /*<<< orphan*/ st_mode;
};
typedef int mode_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int S_IFCHR;
int S_IFMT;
int /*<<< orphan*/ S_ISCHR(int /*<<< orphan*/);
int chown(char *, int, int);
scalar_t__ errno;
int /*<<< orphan*/ error(int, scalar_t__, char *, ...);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ major(int /*<<< orphan*/);
int /*<<< orphan*/ makedev(int /*<<< orphan*/, int);
int mknod(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, int);
int stat(char *, struct stat *);
void *strtol(char *, char **, int);
int main(int argc, char **argv) {
  int rc;
  mode_t mode = 0660;
  struct stat emlog_stat;
  int size_of_buffer = 8;
  char *file;
  char *number;
  char *end_of_number;
  int emlog_max_size = 0;
  FILE *max_size_file = NULL;
  uid_t uid = -1;
  if (argc < 2 || argc > 5) {
    error(1, 0, "usage: mkemlog <logdevname> [size_in_kilobytes] [mode] [uid]");
  }
  file = argv[1];
  max_size_file = fopen("/sys/module/emlog/parameters/emlog_max_size", "r");
  if (max_size_file == NULL)
    error(1, errno, "Emlog module not loaded\n");
  rc = fscanf(max_size_file, "%d", &emlog_max_size);
  if (rc != 1)
    error(1, errno, "Unable to get emlog max size\n");
  fclose(max_size_file);
  max_size_file = NULL;
  if (argc > 2) {
    errno = 0;
    number = argv[2];
    size_of_buffer = strtol(number, &end_of_number, 10);
    if (errno) {
      error(1, errno,
            "Invalid size provided\n"
            "usage: mkemlog <logdevname> [size_in_kilobytes] [mode] [uid]");
    }
    if (end_of_number == number) {
      error(1, 0,
            "Invalid size provided\n"
            "usage: mkemlog <logdevname> [size_in_kilobytes] [mode] [uid]");
    }
    if (size_of_buffer < 1 || size_of_buffer > emlog_max_size) {
      error(1, 0,
            "Invalid size provided must be a value between 1 and %d\n"
            "usage: mkemlog <logdevname> [size_in_kilobytes] [mode] [uid]",
            emlog_max_size);
    }
  }
  if (argc > 3) {
    errno = 0;
    number = argv[3];
    mode = strtol(number, &end_of_number, 8);
    if (errno) {
      error(1, errno,
            "Invalid mode provided\n"
            "usage: mkemlog <logdevname> [size_in_kilobytes] [mode] [uid]");
    }
    if (end_of_number == number || S_IFMT & mode) {
      error(1, 0,
            "Invalid mode provided\n"
            "usage: mkemlog <logdevname> [size_in_kilobytes] [mode] [uid]");
    }
  }
  if (argc > 4) {
    errno = 0;
    number = argv[4];
    uid = strtol(number, &end_of_number, 10);
    if (errno) {
      error(1, errno,
            "Invalid uid provided\n"
            "usage: mkemlog <logdevname> [size_in_kilobytes] [mode] [uid]");
    }
    if (end_of_number == number) {
      error(1, 0,
            "Invalid uid provided\n"
            "usage: mkemlog <logdevname> [size_in_kilobytes] [mode] [uid]");
    }
  }
  rc = stat("/dev/emlog", &emlog_stat);
  if (rc == -1) {
    error(1, errno,
          "stat: "
          "/dev/emlog");
  }
  if (!S_ISCHR(emlog_stat.st_mode)) {
    error(1, 0,
          "/dev/emlog"
          " is not a valid emlog device\n");
  }
  rc = mknod(file, mode | S_IFCHR,
             makedev(major(emlog_stat.st_rdev), size_of_buffer));
  if (rc == -1) {
    error(1, errno, "mknod: %s", file);
  }
  if (uid != -1) {
    rc = chown(file, uid, -1);
    if (rc == -1) {
      error(1, errno, "chown: %s", file);
    }
  }
  printf("Log device %s created with buffer size of %d KiB\n", file,
         size_of_buffer);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1b0,-0x18(%rbp)
movl   $0x8,-0x24(%rbp)
movl   $0x0,-0x44(%rbp)
movq   $0x0,-0x50(%rbp)
movl   $0xffffffff,-0x54(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     120e <main+0x4e>
cmpl   $0x5,-0x8(%rbp)
jle    1225 <main+0x65>
mov    $0x1,%edi
xor    %eax,%eax
mov    %eax,%esi
lea    0xed4(%rip),%rdx
mov    $0x0,%al
call   10c0 <error@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
lea    0xdc8(%rip),%rdi
lea    0xded(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    1270 <main+0xb0>
mov    0x2d76(%rip),%rax
mov    (%rax),%rsi
mov    $0x1,%edi
lea    0xdc5(%rip),%rdx
mov    $0x0,%al
call   10c0 <error@plt>
mov    -0x50(%rbp),%rdi
lea    0xdcc(%rip),%rsi
lea    -0x44(%rbp),%rdx
call   1060 <fscanf@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
je     12ae <main+0xee>
mov    0x2d38(%rip),%rax
mov    (%rax),%rsi
mov    $0x1,%edi
lea    0xda3(%rip),%rdx
mov    $0x0,%al
call   10c0 <error@plt>
mov    -0x50(%rbp),%rdi
call   1030 <fclose@plt>
movq   $0x0,-0x50(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    1380 <main+0x1c0>
mov    0x2d00(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    $0xa,%edx
call   1090 <strtol@plt>
mov    %eax,-0x24(%rbp)
mov    0x2cd1(%rip),%rax
cmpq   $0x0,(%rax)
je     1326 <main+0x166>
mov    0x2cc0(%rip),%rax
mov    (%rax),%rsi
mov    $0x1,%edi
lea    0xd49(%rip),%rdx
mov    $0x0,%al
call   10c0 <error@plt>
mov    -0x40(%rbp),%rax
cmp    -0x38(%rbp),%rax
jne    134b <main+0x18b>
mov    $0x1,%edi
xor    %eax,%eax
mov    %eax,%esi
lea    0xd24(%rip),%rdx
mov    $0x0,%al
call   10c0 <error@plt>
cmpl   $0x1,-0x24(%rbp)
jl     1361 <main+0x1a1>
mov    -0x24(%rbp),%eax
cmp    -0x44(%rbp),%eax
jle    137b <main+0x1bb>
mov    -0x44(%rbp),%ecx
mov    $0x1,%edi
xor    %eax,%eax
mov    %eax,%esi
lea    0xd47(%rip),%rdx
mov    $0x0,%al
call   10c0 <error@plt>
jmp    1380 <main+0x1c0>
cmpl   $0x3,-0x8(%rbp)
jle    1426 <main+0x266>
mov    0x2c3f(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    $0x8,%edx
call   1090 <strtol@plt>
mov    %eax,-0x18(%rbp)
mov    0x2c10(%rip),%rax
cmpq   $0x0,(%rax)
je     13e7 <main+0x227>
mov    0x2bff(%rip),%rax
mov    (%rax),%rsi
mov    $0x1,%edi
lea    0xd4f(%rip),%rdx
mov    $0x0,%al
call   10c0 <error@plt>
mov    -0x40(%rbp),%rax
cmp    -0x38(%rbp),%rax
je     140a <main+0x24a>
mov    0x2be4(%rip),%rax
mov    (%rax),%eax
and    -0x18(%rbp),%eax
cmp    $0x0,%eax
je     1421 <main+0x261>
mov    $0x1,%edi
xor    %eax,%eax
mov    %eax,%esi
lea    0xd15(%rip),%rdx
mov    $0x0,%al
call   10c0 <error@plt>
jmp    1426 <main+0x266>
cmpl   $0x4,-0x8(%rbp)
jle    14b7 <main+0x2f7>
mov    0x2b99(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    $0xa,%edx
call   1090 <strtol@plt>
mov    %eax,-0x54(%rbp)
mov    0x2b6a(%rip),%rax
cmpq   $0x0,(%rax)
je     148d <main+0x2cd>
mov    0x2b59(%rip),%rax
mov    (%rax),%rsi
mov    $0x1,%edi
lea    0xcfc(%rip),%rdx
mov    $0x0,%al
call   10c0 <error@plt>
mov    -0x40(%rbp),%rax
cmp    -0x38(%rbp),%rax
jne    14b2 <main+0x2f2>
mov    $0x1,%edi
xor    %eax,%eax
mov    %eax,%esi
lea    0xcd7(%rip),%rdx
mov    $0x0,%al
call   10c0 <error@plt>
jmp    14b7 <main+0x2f7>
lea    0xd1c(%rip),%rdi
lea    -0x20(%rbp),%rsi
call   1070 <stat@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    14f1 <main+0x331>
mov    0x2af5(%rip),%rax
mov    (%rax),%rsi
mov    $0x1,%edi
lea    0xcea(%rip),%rdx
mov    $0x0,%al
call   10c0 <error@plt>
mov    -0x1c(%rbp),%edi
call   10a0 <S_ISCHR@plt>
cmp    $0x0,%eax
jne    1519 <main+0x359>
mov    $0x1,%edi
xor    %eax,%eax
mov    %eax,%esi
lea    0xcd3(%rip),%rdx
mov    $0x0,%al
call   10c0 <error@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x18(%rbp),%eax
mov    0x2aad(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x58(%rbp)
mov    -0x20(%rbp),%edi
call   1050 <major@plt>
mov    %eax,%edi
mov    -0x24(%rbp),%esi
call   10e0 <makedev@plt>
mov    -0x60(%rbp),%rdi
mov    -0x58(%rbp),%esi
mov    %eax,%edx
call   1080 <mknod@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    157e <main+0x3be>
mov    0x2a6c(%rip),%rax
mov    (%rax),%rsi
mov    -0x30(%rbp),%rcx
mov    $0x1,%edi
lea    0xc96(%rip),%rdx
mov    $0x0,%al
call   10c0 <error@plt>
cmpl   $0xffffffff,-0x54(%rbp)
je     15cc <main+0x40c>
mov    -0x30(%rbp),%rdi
mov    -0x54(%rbp),%esi
mov    $0xffffffff,%edx
call   10b0 <chown@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    15c7 <main+0x407>
mov    0x2a23(%rip),%rax
mov    (%rax),%rsi
mov    -0x30(%rbp),%rcx
mov    $0x1,%edi
lea    0xc57(%rip),%rdx
mov    $0x0,%al
call   10c0 <error@plt>
jmp    15cc <main+0x40c>
mov    -0x30(%rbp),%rsi
mov    -0x24(%rbp),%edx
lea    0xc47(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbp
mov    %edi,%r13d
movl   $0x0,0xc(%rsp)
lea    -0x6(%r13),%eax
cmp    $0xfffffffb,%eax
ja     11fa <main+0x3a>
lea    0xf06(%rip),%rdx
mov    $0x1,%edi
xor    %esi,%esi
xor    %eax,%eax
call   10c0 <error@plt>
mov    0x8(%rbp),%r15
lea    0xdfb(%rip),%rdi
lea    0xe20(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1236 <main+0x76>
mov    0x2db0(%rip),%rax
mov    (%rax),%rsi
lea    0xe04(%rip),%rdx
mov    $0x1,%edi
xor    %eax,%eax
call   10c0 <error@plt>
lea    0xe0a(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rbx,%rdi
call   1060 <fscanf@plt>
cmp    $0x1,%eax
je     126c <main+0xac>
mov    0x2d7a(%rip),%rax
mov    (%rax),%rsi
lea    0xdea(%rip),%rdx
mov    $0x1,%edi
xor    %eax,%eax
call   10c0 <error@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    $0xffffffff,%ebx
mov    $0x8,%r12d
mov    $0x1b0,%r14d
cmp    $0x3,%r13d
jl     1409 <main+0x249>
mov    %r15,0x18(%rsp)
mov    0x2d35(%rip),%rbx
movq   $0x0,(%rbx)
mov    %rbp,0x10(%rsp)
mov    0x10(%rbp),%r15
mov    %rsp,%rsi
mov    %r15,%rdi
mov    $0xa,%edx
call   1090 <strtol@plt>
mov    %rax,%r12
mov    (%rbx),%rsi
test   %rsi,%rsi
je     12d9 <main+0x119>
lea    0xd9b(%rip),%rdx
mov    $0x1,%edi
xor    %eax,%eax
call   10c0 <error@plt>
cmp    %r15,(%rsp)
jne    12f4 <main+0x134>
lea    0xd82(%rip),%rdx
mov    $0x1,%edi
xor    %esi,%esi
xor    %eax,%eax
call   10c0 <error@plt>
mov    0xc(%rsp),%ecx
test   %r12d,%r12d
mov    $0xffffffff,%ebx
mov    0x18(%rsp),%r15
mov    0x10(%rsp),%rbp
jle    1311 <main+0x151>
cmp    %r12d,%ecx
jge    1326 <main+0x166>
lea    0xda3(%rip),%rdx
mov    $0x1,%edi
xor    %esi,%esi
xor    %eax,%eax
call   10c0 <error@plt>
cmp    $0x4,%r13d
jb     1409 <main+0x249>
mov    0x2c99(%rip),%rbx
movq   $0x0,(%rbx)
mov    0x18(%rbp),%r15
mov    %rsp,%rsi
mov    %r15,%rdi
mov    $0x8,%edx
call   1090 <strtol@plt>
mov    %rax,%r14
mov    (%rbx),%rsi
test   %rsi,%rsi
je     1370 <main+0x1b0>
lea    0xdcb(%rip),%rdx
mov    $0x1,%edi
xor    %eax,%eax
call   10c0 <error@plt>
cmp    %r15,(%rsp)
je     1382 <main+0x1c2>
mov    0x2c63(%rip),%rax
test   %r14d,(%rax)
je     1397 <main+0x1d7>
lea    0xda6(%rip),%rdx
mov    $0x1,%edi
xor    %esi,%esi
xor    %eax,%eax
call   10c0 <error@plt>
cmp    $0x5,%r13d
mov    $0xffffffff,%ebx
mov    0x18(%rsp),%r15
mov    0x10(%rsp),%rax
jb     1409 <main+0x249>
mov    0x2c1d(%rip),%r13
movq   $0x0,0x0(%r13)
mov    0x20(%rax),%rbp
mov    %rsp,%rsi
mov    %rbp,%rdi
mov    $0xa,%edx
call   1090 <strtol@plt>
mov    %rax,%rbx
mov    0x0(%r13),%rsi
test   %rsi,%rsi
je     13ee <main+0x22e>
lea    0xda0(%rip),%rdx
mov    $0x1,%edi
xor    %eax,%eax
call   10c0 <error@plt>
cmp    %rbp,(%rsp)
jne    1409 <main+0x249>
lea    0xd87(%rip),%rdx
mov    $0x1,%edi
xor    %esi,%esi
xor    %eax,%eax
call   10c0 <error@plt>
lea    0xdca(%rip),%rdi
lea    0x20(%rsp),%rsi
call   1070 <stat@plt>
cmp    $0xffffffff,%eax
jne    143c <main+0x27c>
mov    0x2baa(%rip),%rax
mov    (%rax),%rsi
lea    0xda4(%rip),%rdx
mov    $0x1,%edi
xor    %eax,%eax
call   10c0 <error@plt>
mov    0x24(%rsp),%edi
call   10a0 <S_ISCHR@plt>
test   %eax,%eax
jne    145e <main+0x29e>
lea    0xd95(%rip),%rdx
mov    $0x1,%edi
xor    %esi,%esi
xor    %eax,%eax
call   10c0 <error@plt>
mov    0x2b73(%rip),%rax
or     (%rax),%r14d
mov    0x20(%rsp),%edi
call   1050 <major@plt>
mov    %eax,%edi
mov    %r12d,%esi
call   10e0 <makedev@plt>
mov    %r15,%rdi
mov    %r14d,%esi
mov    %eax,%edx
call   1080 <mknod@plt>
cmp    $0xffffffff,%eax
jne    14ad <main+0x2ed>
mov    0x2b3c(%rip),%rax
mov    (%rax),%rsi
lea    0xd6f(%rip),%rdx
mov    $0x1,%edi
mov    %r15,%rcx
xor    %eax,%eax
call   10c0 <error@plt>
cmp    $0xffffffff,%ebx
je     14e6 <main+0x326>
mov    %r15,%rdi
mov    %ebx,%esi
mov    $0xffffffff,%edx
call   10b0 <chown@plt>
cmp    $0xffffffff,%eax
jne    14e6 <main+0x326>
mov    0x2b03(%rip),%rax
mov    (%rax),%rsi
lea    0xd40(%rip),%rdx
mov    $0x1,%edi
mov    %r15,%rcx
xor    %eax,%eax
call   10c0 <error@plt>
lea    0xd34(%rip),%rdi
mov    %r15,%rsi
mov    %r12d,%edx
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32, i32 }
@.str = [61 x i8] c"usage: mkemlog <logdevname> [size_in_kilobytes] [mode] [uid]\00"
@.str.1 = [44 x i8] c"/sys/module/emlog/parameters/emlog_max_size\00"
@.str.2 = [2 x i8] c"r\00"
@errno = global i64 0
@.str.3 = [25 x i8] c"Emlog module not loaded\0A\00"
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [30 x i8] c"Unable to get emlog max size\0A\00"
@.str.6 = [83 x i8] c"Invalid size provided\0Ausage: mkemlog <logdevname> [size_in_kilobytes] [mode] [uid]\00"
@.str.7 = [116 x i8] c"Invalid size provided must be a value between 1 and %d\0Ausage: mkemlog <logdevname> [size_in_kilobytes] [mode] [uid]\00"
@.str.8 = [83 x i8] c"Invalid mode provided\0Ausage: mkemlog <logdevname> [size_in_kilobytes] [mode] [uid]\00"
@S_IFMT = global i32 0
@.str.9 = [82 x i8] c"Invalid uid provided\0Ausage: mkemlog <logdevname> [size_in_kilobytes] [mode] [uid]\00"
@.str.10 = [11 x i8] c"/dev/emlog\00"
@.str.11 = [17 x i8] c"stat: /dev/emlog\00"
@.str.12 = [40 x i8] c"/dev/emlog is not a valid emlog device\0A\00"
@S_IFCHR = global i32 0
@.str.13 = [10 x i8] c"mknod: %s\00"
@.str.14 = [10 x i8] c"chown: %s\00"
@.str.15 = [50 x i8] c"Log device %s created with buffer size of %d KiB\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.stat
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32*
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 432, i32* %7
store i32 8, i32* %9
store i32 0, i32* %13
store i32* null, i32** %14
store i32 -1, i32* %15
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 2
br i1 %17, label %21, label %18
18: ; preds = %2
%19 = load i32, i32* %4
%20 = icmp sgt i32 %19, 5
br i1 %20, label %21, label %23
21: ; preds = %18, %2
%22 = call i32 (i32, i64, i8*, ...) @error(i32 1, i64 0, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0))
br label %23
23: ; preds = %21, %18
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
store i8* %26, i8** %10
%27 = call i32* @fopen(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %27, i32** %14
%28 = load i32*, i32** %14
%29 = icmp eq i32* %28, null
br i1 %29, label %30, label %33
30: ; preds = %23
%31 = load i64, i64* @errno
%32 = call i32 (i32, i64, i8*, ...) @error(i32 1, i64 %31, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
br label %33
33: ; preds = %30, %23
%34 = load i32*, i32** %14
%35 = call i32 @fscanf(i32* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %13)
store i32 %35, i32* %6
%36 = load i32, i32* %6
%37 = icmp ne i32 %36, 1
br i1 %37, label %38, label %41
38: ; preds = %33
%39 = load i64, i64* @errno
%40 = call i32 (i32, i64, i8*, ...) @error(i32 1, i64 %39, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
br label %41
41: ; preds = %38, %33
%42 = load i32*, i32** %14
%43 = call i32 @fclose(i32* %42)
store i32* null, i32** %14
%44 = load i32, i32* %4
%45 = icmp sgt i32 %44, 2
br i1 %45, label %46, label %75
46: ; preds = %41
store i64 0, i64* @errno
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 2
%49 = load i8*, i8** %48
store i8* %49, i8** %11
%50 = load i8*, i8** %11
%51 = call i8* @strtol(i8* %50, i8** %12, i32 10)
%52 = ptrtoint i8* %51 to i32
store i32 %52, i32* %9
%53 = load i64, i64* @errno
%54 = icmp ne i64 %53, 0
br i1 %54, label %55, label %58
55: ; preds = %46
%56 = load i64, i64* @errno
%57 = call i32 (i32, i64, i8*, ...) @error(i32 1, i64 %56, i8* getelementptr inbounds ([83 x i8], [83 x i8]* @.str.6, i64 0, i64 0))
br label %58
58: ; preds = %55, %46
%59 = load i8*, i8** %12
%60 = load i8*, i8** %11
%61 = icmp eq i8* %59, %60
br i1 %61, label %62, label %64
62: ; preds = %58
%63 = call i32 (i32, i64, i8*, ...) @error(i32 1, i64 0, i8* getelementptr inbounds ([83 x i8], [83 x i8]* @.str.6, i64 0, i64 0))
br label %64
64: ; preds = %62, %58
%65 = load i32, i32* %9
%66 = icmp slt i32 %65, 1
br i1 %66, label %71, label %67
67: ; preds = %64
%68 = load i32, i32* %9
%69 = load i32, i32* %13
%70 = icmp sgt i32 %68, %69
br i1 %70, label %71, label %74
71: ; preds = %67, %64
%72 = load i32, i32* %13
%73 = call i32 (i32, i64, i8*, ...) @error(i32 1, i64 0, i8* getelementptr inbounds ([116 x i8], [116 x i8]* @.str.7, i64 0, i64 0), i32 %72)
br label %74
74: ; preds = %71, %67
br label %75
75: ; preds = %74, %41
%76 = load i32, i32* %4
%77 = icmp sgt i32 %76, 3
br i1 %77, label %78, label %102
78: ; preds = %75
store i64 0, i64* @errno
%79 = load i8**, i8*** %5
%80 = getelementptr inbounds i8*, i8** %79, i64 3
%81 = load i8*, i8** %80
store i8* %81, i8** %11
%82 = load i8*, i8** %11
%83 = call i8* @strtol(i8* %82, i8** %12, i32 8)
%84 = ptrtoint i8* %83 to i32
store i32 %84, i32* %7
%85 = load i64, i64* @errno
%86 = icmp ne i64 %85, 0
br i1 %86, label %87, label %90
87: ; preds = %78
%88 = load i64, i64* @errno
%89 = call i32 (i32, i64, i8*, ...) @error(i32 1, i64 %88, i8* getelementptr inbounds ([83 x i8], [83 x i8]* @.str.8, i64 0, i64 0))
br label %90
90: ; preds = %87, %78
%91 = load i8*, i8** %12
%92 = load i8*, i8** %11
%93 = icmp eq i8* %91, %92
br i1 %93, label %99, label %94
94: ; preds = %90
%95 = load i32, i32* @S_IFMT
%96 = load i32, i32* %7
%97 = and i32 %95, %96
%98 = icmp ne i32 %97, 0
br i1 %98, label %99, label %101
99: ; preds = %94, %90
%100 = call i32 (i32, i64, i8*, ...) @error(i32 1, i64 0, i8* getelementptr inbounds ([83 x i8], [83 x i8]* @.str.8, i64 0, i64 0))
br label %101
101: ; preds = %99, %94
br label %102
102: ; preds = %101, %75
%103 = load i32, i32* %4
%104 = icmp sgt i32 %103, 4
br i1 %104, label %105, label %124
105: ; preds = %102
store i64 0, i64* @errno
%106 = load i8**, i8*** %5
%107 = getelementptr inbounds i8*, i8** %106, i64 4
%108 = load i8*, i8** %107
store i8* %108, i8** %11
%109 = load i8*, i8** %11
%110 = call i8* @strtol(i8* %109, i8** %12, i32 10)
%111 = ptrtoint i8* %110 to i32
store i32 %111, i32* %15
%112 = load i64, i64* @errno
%113 = icmp ne i64 %112, 0
br i1 %113, label %114, label %117
114: ; preds = %105
%115 = load i64, i64* @errno
%116 = call i32 (i32, i64, i8*, ...) @error(i32 1, i64 %115, i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.9, i64 0, i64 0))
br label %117
117: ; preds = %114, %105
%118 = load i8*, i8** %12
%119 = load i8*, i8** %11
%120 = icmp eq i8* %118, %119
br i1 %120, label %121, label %123
121: ; preds = %117
%122 = call i32 (i32, i64, i8*, ...) @error(i32 1, i64 0, i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.9, i64 0, i64 0))
br label %123
123: ; preds = %121, %117
br label %124
124: ; preds = %123, %102
%125 = call i32 @stat(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.10, i64 0, i64 0), %struct.stat* %8)
store i32 %125, i32* %6
%126 = load i32, i32* %6
%127 = icmp eq i32 %126, -1
br i1 %127, label %128, label %131
128: ; preds = %124
%129 = load i64, i64* @errno
%130 = call i32 (i32, i64, i8*, ...) @error(i32 1, i64 %129, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.11, i64 0, i64 0))
br label %131
131: ; preds = %128, %124
%132 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 1
%133 = load i32, i32* %132
%134 = call i32 @S_ISCHR(i32 %133)
%135 = icmp ne i32 %134, 0
br i1 %135, label %138, label %136
136: ; preds = %131
%137 = call i32 (i32, i64, i8*, ...) @error(i32 1, i64 0, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.12, i64 0, i64 0))
br label %138
138: ; preds = %136, %131
%139 = load i8*, i8** %10
%140 = load i32, i32* %7
%141 = load i32, i32* @S_IFCHR
%142 = or i32 %140, %141
%143 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%144 = load i32, i32* %143
%145 = call i32 @major(i32 %144)
%146 = load i32, i32* %9
%147 = call i32 @makedev(i32 %145, i32 %146)
%148 = call i32 @mknod(i8* %139, i32 %142, i32 %147)
store i32 %148, i32* %6
%149 = load i32, i32* %6
%150 = icmp eq i32 %149, -1
br i1 %150, label %151, label %155
151: ; preds = %138
%152 = load i64, i64* @errno
%153 = load i8*, i8** %10
%154 = call i32 (i32, i64, i8*, ...) @error(i32 1, i64 %152, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.13, i64 0, i64 0), i8* %153)
br label %155
155: ; preds = %151, %138
%156 = load i32, i32* %15
%157 = icmp ne i32 %156, -1
br i1 %157, label %158, label %169
158: ; preds = %155
%159 = load i8*, i8** %10
%160 = load i32, i32* %15
%161 = call i32 @chown(i8* %159, i32 %160, i32 -1)
store i32 %161, i32* %6
%162 = load i32, i32* %6
%163 = icmp eq i32 %162, -1
br i1 %163, label %164, label %168
164: ; preds = %158
%165 = load i64, i64* @errno
%166 = load i8*, i8** %10
%167 = call i32 (i32, i64, i8*, ...) @error(i32 1, i64 %165, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.14, i64 0, i64 0), i8* %166)
br label %168
168: ; preds = %164, %158
br label %169
169: ; preds = %168, %155
%170 = load i8*, i8** %10
%171 = load i32, i32* %9
%172 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.15, i64 0, i64 0), i8* %170, i32 %171)
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32, i32 }
@.str = [61 x i8] c"usage: mkemlog <logdevname> [size_in_kilobytes] [mode] [uid]\00"
@.str.1 = [44 x i8] c"/sys/module/emlog/parameters/emlog_max_size\00"
@.str.2 = [2 x i8] c"r\00"
@errno = global i64 0
@.str.3 = [25 x i8] c"Emlog module not loaded\0A\00"
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [30 x i8] c"Unable to get emlog max size\0A\00"
@.str.6 = [83 x i8] c"Invalid size provided\0Ausage: mkemlog <logdevname> [size_in_kilobytes] [mode] [uid]\00"
@.str.7 = [116 x i8] c"Invalid size provided must be a value between 1 and %d\0Ausage: mkemlog <logdevname> [size_in_kilobytes] [mode] [uid]\00"
@.str.8 = [83 x i8] c"Invalid mode provided\0Ausage: mkemlog <logdevname> [size_in_kilobytes] [mode] [uid]\00"
@S_IFMT = global i32 0
@.str.9 = [82 x i8] c"Invalid uid provided\0Ausage: mkemlog <logdevname> [size_in_kilobytes] [mode] [uid]\00"
@.str.10 = [11 x i8] c"/dev/emlog\00"
@.str.11 = [17 x i8] c"stat: /dev/emlog\00"
@.str.12 = [40 x i8] c"/dev/emlog is not a valid emlog device\0A\00"
@S_IFCHR = global i32 0
@.str.13 = [10 x i8] c"mknod: %s\00"
@.str.14 = [10 x i8] c"chown: %s\00"
@.str.15 = [50 x i8] c"Log device %s created with buffer size of %d KiB\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = alloca i8*
%5 = alloca i32
%6 = bitcast %struct.stat* %3 to i8*
%7 = bitcast i8** %4 to i8*
%8 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%9 = add i32 %0, -6
%10 = icmp ult i32 %9, -4
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = tail call i32 (i32, i64, i8*, ...) @error(i32 1, i64 0, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %2, %11
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call i32* @fopen(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = load i64, i64* @errno
%20 = tail call i32 (i32, i64, i8*, ...) @error(i32 1, i64 %19, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
br label %21
21: ; preds = %18, %13
%22 = call i32 @fscanf(i32* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %5)
%23 = icmp eq i32 %22, 1
br i1 %23, label %27, label %24
24: ; preds = %21
%25 = load i64, i64* @errno
%26 = call i32 (i32, i64, i8*, ...) @error(i32 1, i64 %25, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
br label %27
27: ; preds = %24, %21
%28 = call i32 @fclose(i32* %16)
%29 = icmp sgt i32 %0, 2
br i1 %29, label %30, label %90
30: ; preds = %27
store i64 0, i64* @errno
%31 = getelementptr inbounds i8*, i8** %1, i64 2
%32 = load i8*, i8** %31
%33 = call i8* @strtol(i8* %32, i8** %4, i32 10)
%34 = ptrtoint i8* %33 to i64
%35 = trunc i64 %34 to i32
%36 = load i64, i64* @errno
%37 = icmp eq i64 %36, 0
br i1 %37, label %40, label %38
38: ; preds = %30
%39 = call i32 (i32, i64, i8*, ...) @error(i32 1, i64 %36, i8* getelementptr inbounds ([83 x i8], [83 x i8]* @.str.6, i64 0, i64 0))
br label %40
40: ; preds = %38, %30
%41 = load i8*, i8** %4
%42 = icmp eq i8* %41, %32
br i1 %42, label %43, label %45
43: ; preds = %40
%44 = call i32 (i32, i64, i8*, ...) @error(i32 1, i64 0, i8* getelementptr inbounds ([83 x i8], [83 x i8]* @.str.6, i64 0, i64 0))
br label %45
45: ; preds = %43, %40
%46 = icmp slt i32 %35, 1
%47 = load i32, i32* %5
%48 = icmp slt i32 %47, %35
%49 = select i1 %46, i1 true, i1 %48
br i1 %49, label %50, label %52
50: ; preds = %45
%51 = call i32 (i32, i64, i8*, ...) @error(i32 1, i64 0, i8* getelementptr inbounds ([116 x i8], [116 x i8]* @.str.7, i64 0, i64 0), i32 %47)
br label %52
52: ; preds = %45, %50
%53 = icmp ugt i32 %0, 3
br i1 %53, label %54, label %90
54: ; preds = %52
store i64 0, i64* @errno
%55 = getelementptr inbounds i8*, i8** %1, i64 3
%56 = load i8*, i8** %55
%57 = call i8* @strtol(i8* %56, i8** %4, i32 8)
%58 = ptrtoint i8* %57 to i64
%59 = trunc i64 %58 to i32
%60 = load i64, i64* @errno
%61 = icmp eq i64 %60, 0
br i1 %61, label %64, label %62
62: ; preds = %54
%63 = call i32 (i32, i64, i8*, ...) @error(i32 1, i64 %60, i8* getelementptr inbounds ([83 x i8], [83 x i8]* @.str.8, i64 0, i64 0))
br label %64
64: ; preds = %62, %54
%65 = load i8*, i8** %4
%66 = icmp eq i8* %65, %56
br i1 %66, label %71, label %67
67: ; preds = %64
%68 = load i32, i32* @S_IFMT
%69 = and i32 %68, %59
%70 = icmp eq i32 %69, 0
br i1 %70, label %73, label %71
71: ; preds = %67, %64
%72 = call i32 (i32, i64, i8*, ...) @error(i32 1, i64 0, i8* getelementptr inbounds ([83 x i8], [83 x i8]* @.str.8, i64 0, i64 0))
br label %73
73: ; preds = %67, %71
%74 = icmp ugt i32 %0, 4
br i1 %74, label %75, label %90
75: ; preds = %73
store i64 0, i64* @errno
%76 = getelementptr inbounds i8*, i8** %1, i64 4
%77 = load i8*, i8** %76
%78 = call i8* @strtol(i8* %77, i8** %4, i32 10)
%79 = ptrtoint i8* %78 to i64
%80 = trunc i64 %79 to i32
%81 = load i64, i64* @errno
%82 = icmp eq i64 %81, 0
br i1 %82, label %85, label %83
83: ; preds = %75
%84 = call i32 (i32, i64, i8*, ...) @error(i32 1, i64 %81, i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.9, i64 0, i64 0))
br label %85
85: ; preds = %83, %75
%86 = load i8*, i8** %4
%87 = icmp eq i8* %86, %77
br i1 %87, label %88, label %90
88: ; preds = %85
%89 = call i32 (i32, i64, i8*, ...) @error(i32 1, i64 0, i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.9, i64 0, i64 0))
br label %90
90: ; preds = %27, %52, %85, %88, %73
%91 = phi i32 [ %59, %88 ], [ %59, %85 ], [ %59, %73 ], [ 432, %52 ], [ 432, %27 ]
%92 = phi i32 [ %35, %88 ], [ %35, %85 ], [ %35, %73 ], [ %35, %52 ], [ 8, %27 ]
%93 = phi i32 [ %80, %88 ], [ %80, %85 ], [ -1, %73 ], [ -1, %52 ], [ -1, %27 ]
%94 = call i32 @stat(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.10, i64 0, i64 0), %struct.stat* %3)
%95 = icmp eq i32 %94, -1
br i1 %95, label %96, label %99
96: ; preds = %90
%97 = load i64, i64* @errno
%98 = call i32 (i32, i64, i8*, ...) @error(i32 1, i64 %97, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.11, i64 0, i64 0))
br label %99
99: ; preds = %96, %90
%100 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 1
%101 = load i32, i32* %100
%102 = call i32 @S_ISCHR(i32 %101)
%103 = icmp eq i32 %102, 0
br i1 %103, label %104, label %106
104: ; preds = %99
%105 = call i32 (i32, i64, i8*, ...) @error(i32 1, i64 0, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.12, i64 0, i64 0))
br label %106
106: ; preds = %104, %99
%107 = load i32, i32* @S_IFCHR
%108 = or i32 %107, %91
%109 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%110 = load i32, i32* %109
%111 = call i32 @major(i32 %110)
%112 = call i32 @makedev(i32 %111, i32 %92)
%113 = call i32 @mknod(i8* %15, i32 %108, i32 %112)
%114 = icmp eq i32 %113, -1
br i1 %114, label %115, label %118
115: ; preds = %106
%116 = load i64, i64* @errno
%117 = call i32 (i32, i64, i8*, ...) @error(i32 1, i64 %116, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.13, i64 0, i64 0), i8* %15)
br label %118
118: ; preds = %115, %106
%119 = icmp eq i32 %93, -1
br i1 %119, label %126, label %120
120: ; preds = %118
%121 = call i32 @chown(i8* %15, i32 %93, i32 -1)
%122 = icmp eq i32 %121, -1
br i1 %122, label %123, label %126
123: ; preds = %120
%124 = load i64, i64* @errno
%125 = call i32 (i32, i64, i8*, ...) @error(i32 1, i64 %124, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.14, i64 0, i64 0), i8* %15)
br label %126
126: ; preds = %120, %123, %118
%127 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.15, i64 0, i64 0), i8* %15, i32 %92)
ret i32 0
}