#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 atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, int, int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  int a = atoi(argv[1]);
  int b = atoi(argv[2]);
  char *fileName = argv[3];
  if (b == 0)
    goto DivideByZero;
  int result = a / b;
  FILE *file;
  if ((file = fopen(fileName, "w")) == NULL)
    goto FileError;
  else {
    fprintf(file, "%d/%d=%d\n", a, b, result);
    printf("save to file %s : %d/%d=%d\n", fileName, a, b, result);
  }
  fclose(file);
  goto Exit;
DivideByZero:
  printf("Error  : Divide by zero\n");
  goto Exit;
FileError:
  printf("Error : File error\n");
  goto Exit;
Exit:
  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)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    11a1 <main+0x51>
jmp    1212 <main+0xc2>
mov    -0x14(%rbp),%eax
cltd
idivl  -0x18(%rbp)
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe4a(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    11ce <main+0x7e>
jmp    1225 <main+0xd5>
mov    -0x30(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x24(%rbp),%r8d
lea    0xe31(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x24(%rbp),%r8d
lea    0xe05(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
jmp    1233 <main+0xe3>
lea    0xe05(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1233 <main+0xe3>
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1080 <atoi@plt>
mov    %eax,%r12d
mov    0x10(%rbx),%rdi
call   1080 <atoi@plt>
test   %eax,%eax
je     11e4 <main+0x84>
mov    %eax,%ebp
mov    0x18(%rbx),%r14
mov    %r12d,%eax
cltd
idiv   %ebp
mov    %eax,%r15d
lea    0xe66(%rip),%rsi
mov    %r14,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     11ed <main+0x8d>
mov    %rax,%rbx
lea    0xe63(%rip),%rsi
mov    %rax,%rdi
mov    %r12d,%edx
mov    %ebp,%ecx
mov    %r15d,%r8d
call   1060 <fprintf@plt>
lea    0xe3a(%rip),%rdi
mov    %r14,%rsi
mov    %r12d,%edx
mov    %ebp,%ecx
mov    %r15d,%r8d
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    11f9 <main+0x99>
lea    0xe46(%rip),%rdi
jmp    11f4 <main+0x94>
lea    0xe2a(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [10 x i8] c"%d/%d=%d\0A\00"
@.str.2 = [28 x i8] c"save to file %s : %d/%d=%d\0A\00"
@.str.3 = [25 x i8] c"Error : Divide by zero\0A\00"
@.str.4 = [20 x i8] c"Error : File error\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 i8*
%9 = alloca i32
%10 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = call i32 @atoi(i8* %13)
store i32 %14, i32* %6
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 2
%17 = load i8*, i8** %16
%18 = call i32 @atoi(i8* %17)
store i32 %18, i32* %7
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 3
%21 = load i8*, i8** %20
store i8* %21, i8** %8
%22 = load i32, i32* %7
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %2
br label %47
25: ; preds = %2
%26 = load i32, i32* %6
%27 = load i32, i32* %7
%28 = sdiv i32 %26, %27
store i32 %28, i32* %9
%29 = load i8*, i8** %8
%30 = call i32* @fopen(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %30, i32** %10
%31 = icmp eq i32* %30, null
br i1 %31, label %32, label %33
32: ; preds = %25
br label %49
33: ; preds = %25
%34 = load i32*, i32** %10
%35 = load i32, i32* %6
%36 = load i32, i32* %7
%37 = load i32, i32* %9
%38 = call i32 @fprintf(i32* %34, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %35, i32 %36, i32 %37)
%39 = load i8*, i8** %8
%40 = load i32, i32* %6
%41 = load i32, i32* %7
%42 = load i32, i32* %9
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %39, i32 %40, i32 %41, i32 %42)
br label %44
44: ; preds = %33
%45 = load i32*, i32** %10
%46 = call i32 @fclose(i32* %45)
br label %51
47: ; preds = %24
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
br label %51
49: ; preds = %32
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
br label %51
51: ; preds = %49, %47, %44
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [10 x i8] c"%d/%d=%d\0A\00"
@.str.2 = [28 x i8] c"save to file %s : %d/%d=%d\0A\00"
@str = [19 x i8] c"Error : File error\00"
@str.5 = [24 x i8] c"Error : Divide by zero\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = tail call i32 @atoi(i8* %4)
%6 = getelementptr inbounds i8*, i8** %1, i64 2
%7 = load i8*, i8** %6
%8 = tail call i32 @atoi(i8* %7)
%9 = getelementptr inbounds i8*, i8** %1, i64 3
%10 = load i8*, i8** %9
%11 = icmp eq i32 %8, 0
br i1 %11, label %20, label %12
12: ; preds = %2
%13 = sdiv i32 %5, %8
%14 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %22, label %16
16: ; preds = %12
%17 = tail call i32 @fprintf(i32* %14, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %5, i32 %8, i32 %13)
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %10, i32 %5, i32 %8, i32 %13)
%19 = tail call i32 @fclose(i32* %14)
br label %24
20: ; preds = %2
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.5, i64 0, i64 0))
br label %24
22: ; preds = %12
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %24
24: ; preds = %22, %20, %16
ret i32 0
}