#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 */
struct ifreq {
  int /*<<< orphan*/ ifr_name;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ memset(struct ifreq *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
int set_socket(struct ifreq *if_req, char *name) {
  int sd;
  memset(if_req, 0, sizeof(struct ifreq));
  strcpy(if_req->ifr_name, name);
  sd = socket(AF_INET, SOCK_STREAM, 0);
  if (sd < 0) {
    printf("\nError on creating socket");
    return -sd;
  }
  return sd;
}


x86 assembly (clang, -O0):
<set_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11ae <set_socket+0x6e>
lea    0xe64(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
sub    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b4 <set_socket+0x74>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_socket>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
mov    (%rbx),%edi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    0x2e81(%rip),%rax
mov    (%rax),%edi
mov    0x2e68(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    118d <set_socket+0x4d>
lea    0xe7a(%rip),%rdi
call   1040 <printf@plt>
neg    %ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.ifreq = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [26 x i8] c"\0AError on creating socket\00"
define i32 @set_socket(%struct.ifreq* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.ifreq*
%5 = alloca i8*
%6 = alloca i32
store %struct.ifreq* %0, %struct.ifreq** %4
store i8* %1, i8** %5
%7 = load %struct.ifreq*, %struct.ifreq** %4
%8 = call i32 @memset(%struct.ifreq* %7, i32 0, i32 4)
%9 = load %struct.ifreq*, %struct.ifreq** %4
%10 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %9, i32 0, i32 0
%11 = load i32, i32* %10
%12 = load i8*, i8** %5
%13 = call i32 @strcpy(i32 %11, i8* %12)
%14 = load i32, i32* @AF_INET
%15 = load i32, i32* @SOCK_STREAM
%16 = call i32 @socket(i32 %14, i32 %15, i32 0)
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %2
%20 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%21 = load i32, i32* %6
%22 = sub nsw i32 0, %21
store i32 %22, i32* %3
br label %25
23: ; preds = %2
%24 = load i32, i32* %6
store i32 %24, i32* %3
br label %25
25: ; preds = %23, %19
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
%struct.ifreq = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [26 x i8] c"\0AError on creating socket\00"
define i32 @set_socket(%struct.ifreq* %0, i8* %1) {
%3 = tail call i32 @memset(%struct.ifreq* %0, i32 0, i32 4)
%4 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %0, i64 0, i32 0
%5 = load i32, i32* %4
%6 = tail call i32 @strcpy(i32 %5, i8* %1)
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_STREAM
%9 = tail call i32 @socket(i32 %7, i32 %8, i32 0)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%13 = sub nsw i32 0, %9
br label %14
14: ; preds = %2, %11
%15 = phi i32 [ %13, %11 ], [ %9, %2 ]
ret i32 %15
}