#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 atoi(char *);
int getopt(int, char **, char *);
char *optarg;
int /*<<< orphan*/ syslog(int, char *, int, int);
int /*<<< orphan*/ usage();
int main(int argc, char *argv[]) {
  int i;
  int opt;
  int bRollingSev = 0;
  int sev = 6;
  int msgs = 500;
  while ((opt = getopt(argc, argv, "m:s:")) != -1) {
    switch (opt) {
    case 's':
      if (*optarg == 'r') {
        bRollingSev = 1;
        sev = 0;
      } else
        sev = atoi(optarg);
      break;
    case 'm':
      msgs = atoi(optarg);
      break;
    default:
      usage();
      break;
    }
  }
  for (i = 0; i < msgs; ++i) {
    syslog(sev % 8, "test message nbr %d, severity=%d", i, sev % 8);
    if (bRollingSev)
      sev++;
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x6,-0x20(%rbp)
movl   $0x1f4,-0x24(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe87(%rip),%rdx
call   1050 <getopt@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
je     1212 <main+0xd2>
mov    -0x18(%rbp),%eax
mov    %eax,-0x28(%rbp)
sub    $0x6d,%eax
je     11ef <main+0xaf>
jmp    119e <main+0x5e>
mov    -0x28(%rbp),%eax
sub    $0x73,%eax
jne    1206 <main+0xc6>
jmp    11af <main+0x6f>
mov    0x2e42(%rip),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x72,%eax
jne    11d8 <main+0x98>
movl   $0x1,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
jmp    11ea <main+0xaa>
mov    0x2e19(%rip),%rax
mov    (%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x20(%rbp)
jmp    120d <main+0xcd>
mov    0x2e02(%rip),%rax
mov    (%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x24(%rbp)
jmp    120d <main+0xcd>
mov    $0x0,%al
call   1040 <usage@plt>
jmp    116b <main+0x2b>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    127a <main+0x13a>
mov    -0x20(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %edx,%ecx
mov    -0x2c(%rbp),%edx
lea    0xdb6(%rip),%rsi
call   1030 <syslog@plt>
cmpl   $0x0,-0x1c(%rbp)
je     1267 <main+0x127>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    126c <main+0x12c>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1219 <main+0xd9>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,%ebp
mov    $0x1f4,%r14d
mov    $0x6,%ebx
lea    0xe9e(%rip),%r12
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebp,%edi
mov    %r15,%rsi
mov    %r12,%rdx
call   1050 <getopt@plt>
cmp    $0x73,%eax
je     1195 <main+0x55>
cmp    $0x6d,%eax
je     11ad <main+0x6d>
cmp    $0xffffffff,%eax
je     11cb <main+0x8b>
xor    %eax,%eax
call   1040 <usage@plt>
jmp    1170 <main+0x30>
mov    0x2e5c(%rip),%rax
mov    (%rax),%rdi
cmpb   $0x72,(%rdi)
je     11c1 <main+0x81>
call   1060 <atoi@plt>
mov    %eax,%ebx
jmp    1170 <main+0x30>
mov    0x2e44(%rip),%rax
mov    (%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,%r14d
jmp    1170 <main+0x30>
xor    %ebx,%ebx
mov    $0x1,%r13d
jmp    1170 <main+0x30>
test   %r14d,%r14d
jle    1206 <main+0xc6>
xor    %ebp,%ebp
lea    0xe2c(%rip),%r15
nopl   0x0(%rax)
lea    0x7(%rbx),%eax
test   %ebx,%ebx
cmovns %ebx,%eax
and    $0xfffffff8,%eax
mov    %ebx,%ecx
sub    %eax,%ecx
mov    %ecx,%edi
mov    %r15,%rsi
mov    %ebp,%edx
call   1030 <syslog@plt>
add    %r13d,%ebx
add    $0x1,%ebp
cmp    %ebp,%r14d
jne    11e0 <main+0xa0>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"m:s:\00"
@optarg = global i8* null
@.str.1 = [33 x i8] c"test message nbr %d, severity=%d\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 i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
store i32 6, i32* %9
store i32 500, i32* %10
br label %11
11: ; preds = %33, %2
%12 = load i32, i32* %4
%13 = load i8**, i8*** %5
%14 = call i32 @getopt(i32 %12, i8** %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 %14, i32* %7
%15 = icmp ne i32 %14, -1
br i1 %15, label %16, label %34
16: ; preds = %11
%17 = load i32, i32* %7
switch i32 %17, label %31 [
i32 115, label %18
i32 109, label %28
]
18: ; preds = %16
%19 = load i8*, i8** @optarg
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 114
br i1 %22, label %23, label %24
23: ; preds = %18
store i32 1, i32* %8
store i32 0, i32* %9
br label %27
24: ; preds = %18
%25 = load i8*, i8** @optarg
%26 = call i32 @atoi(i8* %25)
store i32 %26, i32* %9
br label %27
27: ; preds = %24, %23
br label %33
28: ; preds = %16
%29 = load i8*, i8** @optarg
%30 = call i32 @atoi(i8* %29)
store i32 %30, i32* %10
br label %33
31: ; preds = %16
%32 = call i32 (...) @usage()
br label %33
33: ; preds = %31, %28, %27
br label %11
34: ; preds = %11
store i32 0, i32* %6
br label %35
35: ; preds = %52, %34
%36 = load i32, i32* %6
%37 = load i32, i32* %10
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %55
39: ; preds = %35
%40 = load i32, i32* %9
%41 = srem i32 %40, 8
%42 = load i32, i32* %6
%43 = load i32, i32* %9
%44 = srem i32 %43, 8
%45 = call i32 @syslog(i32 %41, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %42, i32 %44)
%46 = load i32, i32* %8
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %51
48: ; preds = %39
%49 = load i32, i32* %9
%50 = add nsw i32 %49, 1
store i32 %50, i32* %9
br label %51
51: ; preds = %48, %39
br label %52
52: ; preds = %51
%53 = load i32, i32* %6
%54 = add nsw i32 %53, 1
store i32 %54, i32* %6
br label %35
55: ; preds = %35
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"m:s:\00"
@optarg = global i8* null
@.str.1 = [33 x i8] c"test message nbr %d, severity=%d\00"
define i32 @main(i32 %0, i8** %1) {
br label %3
3: ; preds = %16, %2
%4 = phi i32 [ 0, %2 ], [ 1, %16 ]
%5 = phi i32 [ 6, %2 ], [ 0, %16 ]
%6 = phi i32 [ 500, %2 ], [ %11, %16 ]
br label %7
7: ; preds = %3, %20
%8 = phi i32 [ %5, %3 ], [ %21, %20 ]
%9 = phi i32 [ %6, %3 ], [ %11, %20 ]
br label %10
10: ; preds = %7, %22
%11 = phi i32 [ %9, %7 ], [ %24, %22 ]
br label %12
12: ; preds = %10, %25
%13 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
switch i32 %13, label %25 [
i32 -1, label %14
i32 115, label %16
i32 109, label %22
]
14: ; preds = %12
%15 = icmp sgt i32 %11, 0
br i1 %15, label %27, label %35
16: ; preds = %12
%17 = load i8*, i8** @optarg
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 114
br i1 %19, label %3, label %20
20: ; preds = %16
%21 = tail call i32 @atoi(i8* %17)
br label %7
22: ; preds = %12
%23 = load i8*, i8** @optarg
%24 = tail call i32 @atoi(i8* %23)
br label %10
25: ; preds = %12
%26 = tail call i32 (...) @usage()
br label %12
27: ; preds = %14, %27
%28 = phi i32 [ %32, %27 ], [ %8, %14 ]
%29 = phi i32 [ %33, %27 ], [ 0, %14 ]
%30 = srem i32 %28, 8
%31 = tail call i32 @syslog(i32 %30, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %29, i32 %30)
%32 = add nsw i32 %28, %4
%33 = add nuw nsw i32 %29, 1
%34 = icmp eq i32 %33, %11
br i1 %34, label %35, label %27
35: ; preds = %27, %14
ret i32 0
}