#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 */

/* Variables and functions */
int O_CREAT;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int open(char *, int);
int /*<<< orphan*/ printf(char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(void) {
  int fd1, fd2, fd3;
  fd1 = socket(PF_INET, SOCK_STREAM, 0);
  fd2 = open("test.dat", O_CREAT | O_WRONLY | O_TRUNC);
  fd3 = socket(PF_INET, SOCK_DGRAM, 0);
  printf("file descriptor 1: %d\n", fd1);
  printf("file descriptor 2: %d\n", fd2);
  printf("file descriptor 3: %d\n", fd3);
  close(fd1);
  close(fd2);
  close(fd3);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
mov    0x2e69(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e86(%rip),%rax
mov    (%rax),%esi
mov    0x2e35(%rip),%rax
or     (%rax),%esi
mov    0x2e6c(%rip),%rax
or     (%rax),%esi
lea    0xe73(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
mov    0x2e33(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe4e(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%esi
lea    0xe56(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%esi
lea    0xe5e(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
mov    -0x10(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    0x2e75(%rip),%rbx
mov    (%rbx),%edi
mov    0x2e74(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    0x2e94(%rip),%rcx
mov    0x2e45(%rip),%rdx
mov    (%rdx),%esi
or     (%rcx),%esi
mov    %eax,%r14d
mov    0x2e77(%rip),%rax
or     (%rax),%esi
lea    0xe7e(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%ebp
mov    (%rbx),%edi
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %eax,%ebx
lea    0xe65(%rip),%rdi
mov    %r14d,%esi
call   1030 <printf@plt>
lea    0xe6d(%rip),%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
lea    0xe76(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    %r14d,%edi
call   1040 <close@plt>
mov    %ebp,%edi
call   1040 <close@plt>
mov    %ebx,%edi
call   1040 <close@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [9 x i8] c"test.dat\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [23 x i8] c"file descriptor 1: %d\0A\00"
@.str.2 = [23 x i8] c"file descriptor 2: %d\0A\00"
@.str.3 = [23 x i8] c"file descriptor 3: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = load i32, i32* @PF_INET
%6 = load i32, i32* @SOCK_STREAM
%7 = call i32 @socket(i32 %5, i32 %6, i32 0)
store i32 %7, i32* %2
%8 = load i32, i32* @O_CREAT
%9 = load i32, i32* @O_WRONLY
%10 = or i32 %8, %9
%11 = load i32, i32* @O_TRUNC
%12 = or i32 %10, %11
%13 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %12)
store i32 %13, i32* %3
%14 = load i32, i32* @PF_INET
%15 = load i32, i32* @SOCK_DGRAM
%16 = call i32 @socket(i32 %14, i32 %15, i32 0)
store i32 %16, i32* %4
%17 = load i32, i32* %2
%18 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %17)
%19 = load i32, i32* %3
%20 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = load i32, i32* %4
%22 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %21)
%23 = load i32, i32* %2
%24 = call i32 @close(i32 %23)
%25 = load i32, i32* %3
%26 = call i32 @close(i32 %25)
%27 = load i32, i32* %4
%28 = call i32 @close(i32 %27)
ret i32 0
}

LLVM IR (-O2):
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [9 x i8] c"test.dat\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [23 x i8] c"file descriptor 1: %d\0A\00"
@.str.2 = [23 x i8] c"file descriptor 2: %d\0A\00"
@.str.3 = [23 x i8] c"file descriptor 3: %d\0A\00"
define i32 @main() {
%1 = load i32, i32* @PF_INET
%2 = load i32, i32* @SOCK_STREAM
%3 = tail call i32 @socket(i32 %1, i32 %2, i32 0)
%4 = load i32, i32* @O_CREAT
%5 = load i32, i32* @O_WRONLY
%6 = or i32 %5, %4
%7 = load i32, i32* @O_TRUNC
%8 = or i32 %6, %7
%9 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = load i32, i32* @PF_INET
%11 = load i32, i32* @SOCK_DGRAM
%12 = tail call i32 @socket(i32 %10, i32 %11, i32 0)
%13 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %3)
%14 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %9)
%15 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %12)
%16 = tail call i32 @close(i32 %3)
%17 = tail call i32 @close(i32 %9)
%18 = tail call i32 @close(i32 %12)
ret i32 0
}