#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 *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ strcat(char *, char *);
void writeMyPort(int port) {
  char filename[1024] = "";
  strcat(filename, "./control/");
  strcat(filename, "port");
  FILE *file;
  if ((file = fopen(filename, "w")) == NULL) {
    perror("Cannot open file.");
    exit(1);
  }
  fprintf(file, "%d", port);
  printf("\n%d\n", port);
  fclose(file);
}


x86 assembly (clang, -O0):
<writeMyPort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
lea    -0x410(%rbp),%rdi
lea    0xe51(%rip),%rsi
call   1090 <strcat@plt>
lea    -0x410(%rbp),%rdi
lea    0xe49(%rip),%rsi
call   1090 <strcat@plt>
lea    -0x410(%rbp),%rdi
lea    0xe3b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x418(%rbp)
cmp    $0x0,%rax
jne    1201 <writeMyPort+0x81>
lea    0xe20(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x418(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe12(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x4(%rbp),%esi
lea    0xe06(%rip),%rdi
call   1040 <printf@plt>
mov    -0x418(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeMyPort>:
push   %rbp
push   %rbx
sub    $0x408,%rsp
mov    %edi,%ebp
mov    %rsp,%rbx
mov    $0x400,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
lea    0xe5c(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strcat@plt>
lea    0xe58(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strcat@plt>
lea    0xe4e(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     1203 <writeMyPort+0x83>
mov    %rax,%rbx
lea    0xe4b(%rip),%rsi
mov    %rax,%rdi
mov    %ebp,%edx
call   1060 <fprintf@plt>
lea    0xe3d(%rip),%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x408,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe08(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"./control/\00"
@.str.1 = [5 x i8] c"port\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [18 x i8] c"Cannot open file.\00"
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [5 x i8] c"\0A%d\0A\00"
define void @writeMyPort(i32 %0) {
%2 = alloca i32
%3 = alloca [1024 x i8]
%4 = alloca i32*
store i32 %0, i32* %2
%5 = bitcast [1024 x i8]* %3 to i8*
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%7 = call i32 @strcat(i8* %6, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%9 = call i32 @strcat(i8* %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %11, i32** %4
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %1
%14 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %1
%17 = load i32*, i32** %4
%18 = load i32, i32* %2
%19 = call i32 @fprintf(i32* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %18)
%20 = load i32, i32* %2
%21 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %20)
%22 = load i32*, i32** %4
%23 = call i32 @fclose(i32* %22)
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"./control/\00"
@.str.1 = [5 x i8] c"port\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [18 x i8] c"Cannot open file.\00"
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [5 x i8] c"\0A%d\0A\00"
define void @writeMyPort(i32 %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = call i32 @strcat(i8* %3, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @strcat(i8* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %1
%12 = call i32 @fprintf(i32* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %0)
%13 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %0)
%14 = call i32 @fclose(i32* %6)
ret void
}