#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*/ buffer;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ fwrite(short *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int sscanf(char *, char *, double *, double *, short *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  struct header {
    int version;
    int pasx;
    int pasy;
    int xmin;
    int ymin;
    int xmax;
    int ymax;
    int p1;
    int p2;
    int p3;
    int p4;
    int p5;
  };
  char EtopoPath[1024];
  FILE *EtopoFile;
  char EtopoCompPath[1024];
  FILE *EtopoCompFile;
  char buffer[1024];
  short int z;
  double x, y;
  int c;
  if (argc < 2 || argc > 3) {
    fprintf(stderr, "Sorry !!\n");
    fprintf(stderr, "Usage:  compile_etopo file\n\n");
    return 0;
  }
  sprintf(EtopoPath, "%s", argv[1]);
  if ((EtopoFile = fopen(EtopoPath, "rb")) == NULL) {
    fprintf(stderr, "Impossible d'ouvrir le fichier %s\n", EtopoPath);
    return 0;
  }
  sprintf(EtopoCompPath, "%s.dat", EtopoPath);
  if ((EtopoCompFile = fopen(EtopoCompPath, "wb")) == NULL) {
    fprintf(stderr, "Impossible d'ouvrir le fichier %s\n", EtopoCompPath);
    return 0;
  }
  c = 0;
  while (fgets(buffer, sizeof(buffer), EtopoFile)) {
    if (sscanf(buffer, "%lf, %lf, %hd", &x, &y, &z) == 3) {
      fwrite(&z, sizeof(short int), 1, EtopoCompFile);
      c++;
    } else {
      printf("%s", buffer);
      printf("c: %d\n", c);
      printf("x: %lf y: %lf z: %d\n", x, y, z);
      break;
    }
  }
  fclose(EtopoFile);
  fclose(EtopoCompFile);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     11ad <main+0x2d>
cmpl   $0x3,-0x8(%rbp)
jle    11e7 <main+0x67>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
lea    0xe43(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
lea    0xe36(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    13bd <main+0x23d>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe2a(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x410(%rbp),%rdi
lea    0xe1a(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x418(%rbp)
cmp    $0x0,%rax
jne    1250 <main+0xd0>
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
lea    -0x410(%rbp),%rdx
lea    0xdf0(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    13bd <main+0x23d>
lea    -0x820(%rbp),%rdi
lea    -0x410(%rbp),%rdx
lea    0xdeb(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x820(%rbp),%rdi
lea    0xddf(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x828(%rbp)
cmp    $0x0,%rax
jne    12b8 <main+0x138>
mov    0x2d4b(%rip),%rax
mov    (%rax),%edi
lea    -0x820(%rbp),%rdx
lea    0xd88(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    13bd <main+0x23d>
movl   $0x0,-0xc4c(%rbp)
lea    -0xc30(%rbp),%rdi
mov    -0x418(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     139e <main+0x21e>
lea    -0xc30(%rbp),%rdi
lea    0xd68(%rip),%rsi
lea    -0xc40(%rbp),%rdx
lea    -0xc48(%rbp),%rcx
lea    -0xc32(%rbp),%r8
call   1070 <sscanf@plt>
cmp    $0x3,%eax
jne    1346 <main+0x1c6>
mov    -0x828(%rbp),%rcx
lea    -0xc32(%rbp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
call   10a0 <fwrite@plt>
mov    -0xc4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc4c(%rbp)
jmp    1399 <main+0x219>
lea    -0xc30(%rbp),%rsi
lea    0xcd3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc4c(%rbp),%esi
lea    0xd00(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movsd  -0xc40(%rbp),%xmm0
ff
movsd  -0xc48(%rbp),%xmm1
ff
movswl -0xc32(%rbp),%esi
lea    0xce2(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
jmp    139e <main+0x21e>
jmp    12c2 <main+0x142>
mov    -0x418(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x828(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xc28,%rsp
add    $0xfffffffc,%edi
cmp    $0xfffffffd,%edi
ja     11d5 <main+0x45>
mov    0x2e30(%rip),%rbx
mov    (%rbx),%edi
lea    0xe47(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    (%rbx),%edi
lea    0xe41(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    134b <main+0x1bb>
mov    0x8(%rsi),%rsi
lea    0x420(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0xe3a(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     12be <main+0x12e>
mov    %rax,%r12
lea    0xe45(%rip),%rsi
lea    0x820(%rsp),%rbx
lea    0x420(%rsp),%rdx
mov    %rbx,%rdi
call   10a0 <sprintf@plt>
lea    0xe2d(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     12d8 <main+0x148>
mov    %rax,%r14
lea    0x20(%rsp),%rdi
mov    $0x400,%esi
mov    %r12,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     133b <main+0x1ab>
xor    %ebp,%ebp
lea    0x20(%rsp),%rbx
lea    0x10(%rsp),%r15
lea    0xe(%rsp),%r13
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
lea    0xde0(%rip),%rsi
lea    0x18(%rsp),%rdx
mov    %r15,%rcx
mov    %r13,%r8
call   1080 <sscanf@plt>
cmp    $0x3,%eax
jne    12f9 <main+0x169>
mov    %r13,%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   10b0 <fwrite@plt>
add    $0x1,%ebp
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r12,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
jne    1270 <main+0xe0>
jmp    133b <main+0x1ab>
mov    0x2d1b(%rip),%rax
mov    (%rax),%edi
lea    0xd5f(%rip),%rsi
lea    0x420(%rsp),%rdx
jmp    12f0 <main+0x160>
mov    0x2d01(%rip),%rax
mov    (%rax),%edi
lea    0xd45(%rip),%rsi
lea    0x820(%rsp),%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    134b <main+0x1bb>
lea    0xd27(%rip),%rdi
lea    0x20(%rsp),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xd55(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
movsd  0x18(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
movswl 0xe(%rsp),%esi
lea    0xd3b(%rip),%rdi
mov    $0x2,%al
call   1050 <printf@plt>
mov    %r12,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0xc28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [10 x i8] c"Sorry !!\0A\00"
@.str.1 = [29 x i8] c"Usage: compile_etopo file\0A\0A\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [3 x i8] c"rb\00"
@.str.4 = [35 x i8] c"Impossible d'ouvrir le fichier %s\0A\00"
@.str.5 = [7 x i8] c"%s.dat\00"
@.str.6 = [3 x i8] c"wb\00"
@.str.7 = [14 x i8] c"%lf, %lf, %hd\00"
@.str.8 = [7 x i8] c"c: %d\0A\00"
@.str.9 = [21 x i8] c"x: %lf y: %lf z: %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i8]
%7 = alloca i32*
%8 = alloca [1024 x i8]
%9 = alloca i32*
%10 = alloca [1024 x i8]
%11 = alloca i16
%12 = alloca double
%13 = alloca double
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 2
br i1 %16, label %20, label %17
17: ; preds = %2
%18 = load i32, i32* %4
%19 = icmp sgt i32 %18, 3
br i1 %19, label %20, label %25
20: ; preds = %17, %2
%21 = load i32, i32* @stderr
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%23 = load i32, i32* @stderr
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %80
25: ; preds = %17
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 @sprintf(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %29)
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%32 = call i32* @fopen(i8* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %32, i32** %7
%33 = icmp eq i32* %32, null
br i1 %33, label %34, label %38
34: ; preds = %25
%35 = load i32, i32* @stderr
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i8* %36)
store i32 0, i32* %3
br label %80
38: ; preds = %25
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%41 = call i32 @sprintf(i8* %39, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* %40)
%42 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%43 = call i32* @fopen(i8* %42, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
store i32* %43, i32** %9
%44 = icmp eq i32* %43, null
br i1 %44, label %45, label %49
45: ; preds = %38
%46 = load i32, i32* @stderr
%47 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i8* %47)
store i32 0, i32* %3
br label %80
49: ; preds = %38
store i32 0, i32* %14
br label %50
50: ; preds = %74, %49
%51 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%52 = load i32*, i32** %7
%53 = call i64 @fgets(i8* %51, i32 1024, i32* %52)
%54 = icmp ne i64 %53, 0
br i1 %54, label %55, label %75
55: ; preds = %50
%56 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%57 = call i32 @sscanf(i8* %56, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), double* %12, double* %13, i16* %11)
%58 = icmp eq i32 %57, 3
br i1 %58, label %59, label %64
59: ; preds = %55
%60 = load i32*, i32** %9
%61 = call i32 @fwrite(i16* %11, i32 2, i32 1, i32* %60)
%62 = load i32, i32* %14
%63 = add nsw i32 %62, 1
store i32 %63, i32* %14
br label %74
64: ; preds = %55
%65 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %65)
%67 = load i32, i32* %14
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i32 %67)
%69 = load double, double* %12
%70 = load double, double* %13
%71 = load i16, i16* %11
%72 = sext i16 %71 to i32
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0), double %69, double %70, i32 %72)
br label %75
74: ; preds = %59
br label %50
75: ; preds = %64, %50
%76 = load i32*, i32** %7
%77 = call i32 @fclose(i32* %76)
%78 = load i32*, i32** %9
%79 = call i32 @fclose(i32* %78)
store i32 0, i32* %3
br label %80
80: ; preds = %75, %45, %34, %20
%81 = load i32, i32* %3
ret i32 %81
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [10 x i8] c"Sorry !!\0A\00"
@.str.1 = [29 x i8] c"Usage: compile_etopo file\0A\0A\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [3 x i8] c"rb\00"
@.str.4 = [35 x i8] c"Impossible d'ouvrir le fichier %s\0A\00"
@.str.5 = [7 x i8] c"%s.dat\00"
@.str.6 = [3 x i8] c"wb\00"
@.str.7 = [14 x i8] c"%lf, %lf, %hd\00"
@.str.8 = [7 x i8] c"c: %d\0A\00"
@.str.9 = [21 x i8] c"x: %lf y: %lf z: %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = alloca i16
%7 = alloca double
%8 = alloca double
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%12 = bitcast i16* %6 to i8*
%13 = bitcast double* %7 to i8*
%14 = bitcast double* %8 to i8*
%15 = add i32 %0, -4
%16 = icmp ult i32 %15, -2
br i1 %16, label %17, label %22
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%20 = load i32, i32* @stderr
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
br label %61
22: ; preds = %2
%23 = getelementptr inbounds i8*, i8** %1, i64 1
%24 = load i8*, i8** %23
%25 = call i8* @strcpy(i8* %9, i8* dereferenceable(1) %24)
%26 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %31
28: ; preds = %22
%29 = load i32, i32* @stderr
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i8* %9)
br label %61
31: ; preds = %22
%32 = call i32 @sprintf(i8* %10, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* %9)
%33 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%34 = icmp eq i32* %33, null
br i1 %34, label %38, label %35
35: ; preds = %31
%36 = call i64 @fgets(i8* %11, i32 1024, i32* %26)
%37 = icmp eq i64 %36, 0
br i1 %37, label %58, label %41
38: ; preds = %31
%39 = load i32, i32* @stderr
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i8* %10)
br label %61
41: ; preds = %35, %45
%42 = phi i32 [ %47, %45 ], [ 0, %35 ]
%43 = call i32 @sscanf(i8* %11, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), double* %7, double* %8, i16* %6)
%44 = icmp eq i32 %43, 3
br i1 %44, label %45, label %50
45: ; preds = %41
%46 = call i32 @fwrite(i16* %6, i32 2, i32 1, i32* %33)
%47 = add nuw nsw i32 %42, 1
%48 = call i64 @fgets(i8* %11, i32 1024, i32* %26)
%49 = icmp eq i64 %48, 0
br i1 %49, label %58, label %41
50: ; preds = %41
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %11)
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i32 %42)
%53 = load double, double* %7
%54 = load double, double* %8
%55 = load i16, i16* %6
%56 = sext i16 %55 to i32
%57 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0), double %53, double %54, i32 %56)
br label %58
58: ; preds = %45, %35, %50
%59 = call i32 @fclose(i32* %26)
%60 = call i32 @fclose(i32* %33)
br label %61
61: ; preds = %58, %38, %28, %17
ret i32 0
}