#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ *strcpy(char *, char *);
void log_update(char *line, char **log, int *n) {
  FILE *fp;
  int i = 0;
  if (strcpy(log[*n % 10], line) == NULL) {
    printf("ERROR while saving the log!\n");
    exit(1984);
  }
  fp = fopen("/tmp/audit.log", "w");
  if (fp == NULL) {
    printf("ERROR while opening the log file!\n");
    exit(180);
  }
  if (*n < 10) {
    for (i = 0; i <= *n; i++) {
      fprintf(fp, "%s", log[i]);
    }
  } else {
    for (i = ((*n + 1) % 10); i != (*n % 10); i = (i + 1) % 10) {
      fprintf(fp, "%s", log[i]);
    }
    fprintf(fp, "%s", log[*n % 10]);
  }
  fclose(fp);
  (*n)++;
  return;
}


x86 assembly (clang, -O0):
<log_update>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    -0x30(%rbp),%rax
movslq %edx,%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
cmp    $0x0,%rax
jne    11c5 <log_update+0x65>
lea    0xe4a(%rip),%rdi
call   1050 <printf@plt>
mov    $0x7c0,%edi
call   1080 <exit@plt>
lea    0xe51(%rip),%rdi
lea    0xe59(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11fd <log_update+0x9d>
lea    0xe40(%rip),%rdi
call   1050 <printf@plt>
mov    $0xb4,%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%rax
cmpl   $0xa,(%rax)
jge    124f <log_update+0xef>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jg     124a <log_update+0xea>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe1a(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1211 <log_update+0xb1>
jmp    12e5 <log_update+0x185>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    -0x34(%rbp),%eax
cmp    %edx,%eax
je     12b4 <log_update+0x154>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xdb8(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x24(%rbp)
jmp    1263 <log_update+0x103>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    -0x40(%rbp),%rax
movslq %edx,%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xd71(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_update>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rsi
movslq (%rdx),%rax
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%eax
cltq
mov    (%r14,%rax,8),%rdi
call   1030 <strcpy@plt>
test   %rax,%rax
je     12b0 <log_update+0x150>
lea    0xe56(%rip),%rdi
lea    0xe5e(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     12c6 <log_update+0x166>
mov    %rax,%r12
mov    (%r15),%ecx
cmp    $0xa,%ecx
jge    11fe <log_update+0x9e>
test   %ecx,%ecx
js     1298 <log_update+0x138>
mov    $0xffffffffffffffff,%rbx
nopl   0x0(%rax)
mov    0x8(%r14,%rbx,8),%rdi
mov    %r12,%rsi
call   1060 <fputs@plt>
movslq (%r15),%rax
add    $0x1,%rbx
cmp    %rax,%rbx
jl     11e0 <log_update+0x80>
jmp    1298 <log_update+0x138>
lea    0x1(%rcx),%eax
mov    $0xcccccccd,%edx
imul   %rdx,%rax
shr    $0x23,%rax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
neg    %eax
add    %ecx,%eax
add    $0x1,%eax
mov    %ecx,%esi
imul   %rdx,%rsi
shr    $0x23,%rsi
add    %esi,%esi
lea    (%rsi,%rsi,4),%edx
nopl   0x0(%rax)
sub    %edx,%ecx
cmp    %ecx,%eax
je     128a <log_update+0x12a>
movslq %eax,%rbx
mov    (%r14,%rbx,8),%rdi
mov    %r12,%rsi
call   1060 <fputs@plt>
mov    %ebx,%eax
add    $0x1,%eax
cltq
imul   $0x66666667,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
neg    %eax
add    %ebx,%eax
add    $0x1,%eax
movslq (%r15),%rcx
imul   $0x66666667,%rcx,%rdx
mov    %rdx,%rsi
shr    $0x3f,%rsi
sar    $0x22,%rdx
add    %esi,%edx
add    %edx,%edx
lea    (%rdx,%rdx,4),%edx
jmp    1230 <log_update+0xd0>
cltq
mov    (%r14,%rax,8),%rdi
mov    %r12,%rsi
call   1060 <fputs@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
addl   $0x1,(%r15)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xd7c(%rip),%rdi
call   1040 <puts@plt>
mov    $0x7c0,%edi
call   1080 <exit@plt>
lea    0xd44(%rip),%rdi
call   1040 <puts@plt>
mov    $0xb4,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [29 x i8] c"ERROR while saving the log!\0A\00"
@.str.1 = [15 x i8] c"/tmp/audit.log\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [35 x i8] c"ERROR while opening the log file!\0A\00"
@.str.4 = [3 x i8] c"%s\00"
define void @log_update(i8* %0, i8** %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
store i8* %0, i8** %4
store i8** %1, i8*** %5
store i32* %2, i32** %6
store i32 0, i32* %8
%9 = load i8**, i8*** %5
%10 = load i32*, i32** %6
%11 = load i32, i32* %10
%12 = srem i32 %11, 10
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8*, i8** %9, i64 %13
%15 = load i8*, i8** %14
%16 = load i8*, i8** %4
%17 = call i32* @strcpy(i8* %15, i8* %16)
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %22
19: ; preds = %3
%20 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%21 = call i32 @exit(i32 1984)
unreachable
22: ; preds = %3
%23 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 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* %23, i32** %7
%24 = load i32*, i32** %7
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
%28 = call i32 @exit(i32 180)
unreachable
29: ; preds = %22
%30 = load i32*, i32** %6
%31 = load i32, i32* %30
%32 = icmp slt i32 %31, 10
br i1 %32, label %33, label %51
33: ; preds = %29
store i32 0, i32* %8
br label %34
34: ; preds = %47, %33
%35 = load i32, i32* %8
%36 = load i32*, i32** %6
%37 = load i32, i32* %36
%38 = icmp sle i32 %35, %37
br i1 %38, label %39, label %50
39: ; preds = %34
%40 = load i32*, i32** %7
%41 = load i8**, i8*** %5
%42 = load i32, i32* %8
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8*, i8** %41, i64 %43
%45 = load i8*, i8** %44
%46 = call i32 @fprintf(i32* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %45)
br label %47
47: ; preds = %39
%48 = load i32, i32* %8
%49 = add nsw i32 %48, 1
store i32 %49, i32* %8
br label %34
50: ; preds = %34
br label %84
51: ; preds = %29
%52 = load i32*, i32** %6
%53 = load i32, i32* %52
%54 = add nsw i32 %53, 1
%55 = srem i32 %54, 10
store i32 %55, i32* %8
br label %56
56: ; preds = %70, %51
%57 = load i32, i32* %8
%58 = load i32*, i32** %6
%59 = load i32, i32* %58
%60 = srem i32 %59, 10
%61 = icmp ne i32 %57, %60
br i1 %61, label %62, label %74
62: ; preds = %56
%63 = load i32*, i32** %7
%64 = load i8**, i8*** %5
%65 = load i32, i32* %8
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8*, i8** %64, i64 %66
%68 = load i8*, i8** %67
%69 = call i32 @fprintf(i32* %63, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %68)
br label %70
70: ; preds = %62
%71 = load i32, i32* %8
%72 = add nsw i32 %71, 1
%73 = srem i32 %72, 10
store i32 %73, i32* %8
br label %56
74: ; preds = %56
%75 = load i32*, i32** %7
%76 = load i8**, i8*** %5
%77 = load i32*, i32** %6
%78 = load i32, i32* %77
%79 = srem i32 %78, 10
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds i8*, i8** %76, i64 %80
%82 = load i8*, i8** %81
%83 = call i32 @fprintf(i32* %75, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %82)
br label %84
84: ; preds = %74, %50
%85 = load i32*, i32** %7
%86 = call i32 @fclose(i32* %85)
%87 = load i32*, i32** %6
%88 = load i32, i32* %87
%89 = add nsw i32 %88, 1
store i32 %89, i32* %87
ret void
}

LLVM IR (-O2):
@.str.1 = [15 x i8] c"/tmp/audit.log\00"
@.str.2 = [2 x i8] c"w\00"
@str = [34 x i8] c"ERROR while opening the log file!\00"
@str.5 = [28 x i8] c"ERROR while saving the log!\00"
define void @log_update(i8* %0, i8** nocapture %1, i32* nocapture %2) {
%4 = load i32, i32* %2
%5 = srem i32 %4, 10
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds i8*, i8** %1, i64 %6
%8 = load i8*, i8** %7
%9 = tail call i32* @strcpy(i8* %8, i8* %0)
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %3
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.5, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1984)
unreachable
14: ; preds = %3
%15 = tail call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
%19 = tail call i32 @exit(i32 180)
unreachable
20: ; preds = %14
%21 = load i32, i32* %2
%22 = icmp slt i32 %21, 10
br i1 %22, label %28, label %23
23: ; preds = %20
%24 = add nuw nsw i32 %21, 1
%25 = urem i32 %24, 10
%26 = urem i32 %21, 10
%27 = icmp eq i32 %25, %26
br i1 %27, label %50, label %39
28: ; preds = %20
%29 = icmp slt i32 %21, 0
br i1 %29, label %56, label %30
30: ; preds = %28, %30
%31 = phi i64 [ %35, %30 ], [ 0, %28 ]
%32 = getelementptr inbounds i8*, i8** %1, i64 %31
%33 = load i8*, i8** %32
%34 = tail call i32 @fputs(i8* %33, i32* %15)
%35 = add nuw nsw i64 %31, 1
%36 = load i32, i32* %2
%37 = sext i32 %36 to i64
%38 = icmp slt i64 %31, %37
br i1 %38, label %30, label %56
39: ; preds = %23, %39
%40 = phi i32 [ %46, %39 ], [ %25, %23 ]
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8*, i8** %1, i64 %41
%43 = load i8*, i8** %42
%44 = tail call i32 @fputs(i8* %43, i32* %15)
%45 = add nsw i32 %40, 1
%46 = srem i32 %45, 10
%47 = load i32, i32* %2
%48 = srem i32 %47, 10
%49 = icmp eq i32 %46, %48
br i1 %49, label %50, label %39
50: ; preds = %39, %23
%51 = phi i32 [ %25, %23 ], [ %46, %39 ]
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8*, i8** %1, i64 %52
%54 = load i8*, i8** %53
%55 = tail call i32 @fputs(i8* %54, i32* %15)
br label %56
56: ; preds = %30, %28, %50
%57 = tail call i32 @fclose(i32* %15)
%58 = load i32, i32* %2
%59 = add nsw i32 %58, 1
store i32 %59, i32* %2
ret void
}