#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*/ time_t;
struct tm {
  int tm_hour;
  int tm_min;
  int tm_sec;
};

/* Variables and functions */
int /*<<< orphan*/ bmount(char *);
int /*<<< orphan*/ bumount(char *);
int getpid();
int /*<<< orphan*/ localtime_r(int /*<<< orphan*/ *, struct tm *);
int /*<<< orphan*/ mi_creat(char *);
int /*<<< orphan*/ mi_write(char *, char **, int, scalar_t__);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, int, int, int, int, int);
scalar_t__ strlen(char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  char *buffer2;
  int t_size, i = 0;
  char linea[50];
  bmount("prova");
  int k = 0;
  time_t temps;
  struct tm t;
  mi_creat(argv[1]);
  for (i = 0; i < 100; i++) {
    temps = time(NULL);
    localtime_r(&temps, &t);
    sprintf(linea, "%d:%d:%d Linea numero %i del proceso %i \n", t.tm_hour,
            t.tm_min, t.tm_sec, i, getpid());
    printf("Escriuré: %s \n", linea);
    mi_write(argv[1], &linea, k, strlen(linea));
    k += strlen(linea);
  }
  bumount("prova");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
lea    0xe39(%rip),%rdi
call   10a0 <bmount@plt>
movl   $0x0,-0x64(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <mi_creat@plt>
movl   $0x0,-0x20(%rbp)
cmpl   $0x64,-0x20(%rbp)
jge    12e6 <main+0x146>
xor    %eax,%eax
mov    %eax,%edi
call   10b0 <time@plt>
mov    %eax,-0x68(%rbp)
lea    -0x68(%rbp),%rdi
lea    -0x78(%rbp),%rsi
call   1030 <localtime_r@plt>
lea    -0x60(%rbp),%rax
mov    %rax,-0xa8(%rbp)
mov    -0x78(%rbp),%eax
mov    %eax,-0xa0(%rbp)
mov    -0x74(%rbp),%eax
mov    %eax,-0x9c(%rbp)
mov    -0x70(%rbp),%eax
mov    %eax,-0x98(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x94(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0xa8(%rbp),%rdi
mov    -0xa0(%rbp),%edx
mov    -0x9c(%rbp),%ecx
mov    -0x98(%rbp),%r8d
mov    -0x94(%rbp),%r9d
lea    0xd9e(%rip),%rsi
mov    %eax,(%rsp)
call   10c0 <sprintf@plt>
lea    -0x60(%rbp),%rsi
lea    0xdb5(%rip),%rdi
call   1080 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x90(%rbp)
lea    -0x60(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x64(%rbp),%eax
mov    %eax,-0x7c(%rbp)
lea    -0x60(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x90(%rbp),%rdi
mov    -0x88(%rbp),%rsi
mov    -0x7c(%rbp),%edx
mov    %rax,%rcx
call   1060 <mi_write@plt>
lea    -0x60(%rbp),%rdi
call   1070 <strlen@plt>
mov    %rax,%rcx
movslq -0x64(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x64(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11e7 <main+0x47>
lea    0xd13(%rip),%rdi
call   1090 <bumount@plt>
xor    %eax,%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rsi,%rbx
lea    0xe48(%rip),%rdi
call   10a0 <bmount@plt>
mov    %rbx,0x28(%rsp)
mov    0x8(%rbx),%rdi
call   1050 <mi_creat@plt>
lea    0x30(%rsp),%rbx
xor    %r15d,%r15d
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
xor    %edi,%edi
call   10b0 <time@plt>
mov    %eax,0x14(%rsp)
lea    0x14(%rsp),%rdi
lea    0x18(%rsp),%rsi
call   1030 <localtime_r@plt>
mov    0x18(%rsp),%r12d
mov    0x1c(%rsp),%ebp
mov    0x20(%rsp),%r13d
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,(%rsp)
mov    %rbx,%rdi
lea    0xdea(%rip),%rsi
mov    %r12d,%edx
mov    %ebp,%ecx
mov    %r13d,%r8d
mov    %r14d,%r9d
call   10c0 <sprintf@plt>
lea    0xdfd(%rip),%rdi
mov    %rbx,%rsi
call   1080 <printf@plt>
mov    0x28(%rsp),%rax
mov    0x8(%rax),%rbp
mov    %rbx,%rdi
call   1070 <strlen@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
mov    %rax,%rcx
call   1060 <mi_write@plt>
mov    %rbx,%rdi
call   1070 <strlen@plt>
add    %r15d,%eax
add    $0x1,%r14d
mov    %eax,%r15d
cmp    $0x64,%r14d
jne    11e0 <main+0x40>
lea    0xd80(%rip),%rdi
call   1090 <bumount@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32 }
@.str = [6 x i8] c"prova\00"
@.str.1 = [42 x i8] c"%d:%d:%d Linea numero %i del proceso %i \0A\00"
@.str.2 = [16 x i8] c"Escriur\C3\A9: %s \0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [50 x i8]
%10 = alloca i32
%11 = alloca i32
%12 = alloca %struct.tm
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
%13 = call i32 @bmount(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %10
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @mi_creat(i8* %16)
store i32 0, i32* %8
br label %18
18: ; preds = %50, %2
%19 = load i32, i32* %8
%20 = icmp slt i32 %19, 100
br i1 %20, label %21, label %53
21: ; preds = %18
%22 = call i32 @time(i32* null)
store i32 %22, i32* %11
%23 = call i32 @localtime_r(i32* %11, %struct.tm* %12)
%24 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 0
%25 = getelementptr inbounds %struct.tm, %struct.tm* %12, i32 0, i32 0
%26 = load i32, i32* %25
%27 = getelementptr inbounds %struct.tm, %struct.tm* %12, i32 0, i32 1
%28 = load i32, i32* %27
%29 = getelementptr inbounds %struct.tm, %struct.tm* %12, i32 0, i32 2
%30 = load i32, i32* %29
%31 = load i32, i32* %8
%32 = call i32 (...) @getpid()
%33 = call i32 @sprintf(i8* %24, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i32 %26, i32 %28, i32 %30, i32 %31, i32 %32)
%34 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 0
%35 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %34)
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 1
%38 = load i8*, i8** %37
%39 = bitcast [50 x i8]* %9 to i8**
%40 = load i32, i32* %10
%41 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 0
%42 = call i64 @strlen(i8* %41)
%43 = call i32 @mi_write(i8* %38, i8** %39, i32 %40, i64 %42)
%44 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 0
%45 = call i64 @strlen(i8* %44)
%46 = load i32, i32* %10
%47 = sext i32 %46 to i64
%48 = add nsw i64 %47, %45
%49 = trunc i64 %48 to i32
store i32 %49, i32* %10
br label %50
50: ; preds = %21
%51 = load i32, i32* %8
%52 = add nsw i32 %51, 1
store i32 %52, i32* %8
br label %18
53: ; preds = %18
%54 = call i32 @bumount(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32 }
@.str = [6 x i8] c"prova\00"
@.str.1 = [42 x i8] c"%d:%d:%d Linea numero %i del proceso %i \0A\00"
@.str.2 = [16 x i8] c"Escriur\C3\A9: %s \0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [50 x i8]
%4 = alloca i32
%5 = alloca %struct.tm
%6 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%7 = tail call i32 @bmount(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%8 = bitcast i32* %4 to i8*
%9 = bitcast %struct.tm* %5 to i8*
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @mi_creat(i8* %11)
%13 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 0
%14 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 1
%15 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 2
%16 = bitcast [50 x i8]* %3 to i8**
br label %17
17: ; preds = %2, %17
%18 = phi i32 [ 0, %2 ], [ %33, %17 ]
%19 = phi i32 [ 0, %2 ], [ %34, %17 ]
%20 = call i32 @time(i32* null)
store i32 %20, i32* %4
%21 = call i32 @localtime_r(i32* %4, %struct.tm* %5)
%22 = load i32, i32* %13
%23 = load i32, i32* %14
%24 = load i32, i32* %15
%25 = call i32 (...) @getpid()
%26 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i32 %22, i32 %23, i32 %24, i32 %19, i32 %25)
%27 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %6)
%28 = load i8*, i8** %10
%29 = call i64 @strlen(i8* %6)
%30 = call i32 @mi_write(i8* %28, i8** %16, i32 %18, i64 %29)
%31 = call i64 @strlen(i8* %6)
%32 = trunc i64 %31 to i32
%33 = add i32 %18, %32
%34 = add nuw nsw i32 %19, 1
%35 = icmp eq i32 %34, 100
br i1 %35, label %36, label %17
36: ; preds = %17
%37 = call i32 @bumount(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
ret i32 0
}