#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 uint8_t;

/* Variables and functions */
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *, ...);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
scalar_t__ system(char *);
int bring_up_intf(char *intf) {
  uint8_t retry = 5;
  while (1) {
    char sys_cmd[256];
    memset(sys_cmd, 0, 256);
    snprintf(sys_cmd, 256, "ifconfig | grep %s", intf);
    if (system(sys_cmd) != 0) {
      if (retry-- == 0) {
        printf("Ethernet interface %s is not up.\n", intf);
        return -1;
      }
      printf("trying to bring up interface %s, retry %u times\n", intf,
             5 - retry);
      char cmd[256];
      memset(cmd, 0, 256);
      snprintf(cmd, 256, "ifconfig %s up", intf);
      system(cmd);
      sleep(2);
    } else {
      printf("Ethernet interface %s is up\n", intf);
      break;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<bring_up_intf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x5,-0x14(%rbp)
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x100,%esi
lea    0xe70(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x120(%rbp),%rdi
call   1030 <system@plt>
cmp    $0x0,%rax
je     1241 <bring_up_intf+0xf1>
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
jne    11dd <bring_up_intf+0x8d>
mov    -0x10(%rbp),%rsi
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1264 <bring_up_intf+0x114>
mov    -0x10(%rbp),%rsi
mov    $0x5,%edx
sub    -0x14(%rbp),%edx
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x220(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
lea    -0x220(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x100,%esi
lea    0xe45(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x220(%rbp),%rdi
call   1030 <system@plt>
mov    $0x2,%edi
call   1070 <sleep@plt>
jmp    1258 <bring_up_intf+0x108>
mov    -0x10(%rbp),%rsi
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    125d <bring_up_intf+0x10d>
jmp    1166 <bring_up_intf+0x16>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bring_up_intf>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x208,%rsp
mov    %rdi,%rbx
mov    %rsp,%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
lea    0xe83(%rip),%rdx
mov    %rbp,%rdi
mov    $0x100,%esi
mov    %rbx,%rcx
call   1050 <snprintf@plt>
mov    %rbp,%rdi
call   1030 <system@plt>
test   %rax,%rax
je     1246 <bring_up_intf+0xf6>
mov    $0x1,%ebp
lea    0x100(%rsp),%r12
lea    0xeb4(%rip),%r13
mov    %rsp,%r14
lea    0xe44(%rip),%r15
nopl   0x0(%rax)
cmp    $0x6,%ebp
je     125b <bring_up_intf+0x10b>
lea    0xe65(%rip),%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
mov    %r12,%rdi
mov    $0x100,%esi
mov    %r13,%rdx
mov    %rbx,%rcx
call   1050 <snprintf@plt>
mov    %r12,%rdi
call   1030 <system@plt>
mov    $0x2,%edi
call   1070 <sleep@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
mov    %r14,%rdi
mov    $0x100,%esi
mov    %r15,%rdx
mov    %rbx,%rcx
call   1050 <snprintf@plt>
mov    %r14,%rdi
call   1030 <system@plt>
add    $0x1,%ebp
test   %rax,%rax
jne    11c0 <bring_up_intf+0x70>
lea    0xe28(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
jmp    1271 <bring_up_intf+0x121>
lea    0xdb1(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"ifconfig | grep %s\00"
@.str.1 = [34 x i8] c"Ethernet interface %s is not up.\0A\00"
@.str.2 = [49 x i8] c"trying to bring up interface %s, retry %u times\0A\00"
@.str.3 = [15 x i8] c"ifconfig %s up\00"
@.str.4 = [29 x i8] c"Ethernet interface %s is up\0A\00"
define i32 @bring_up_intf(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [256 x i8]
%6 = alloca [256 x i8]
store i8* %0, i8** %3
store i32 5, i32* %4
br label %7
7: ; preds = %1, %39
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%9 = call i32 @memset(i8* %8, i32 0, i32 256)
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%11 = load i8*, i8** %3
%12 = call i32 @snprintf(i8* %10, i32 256, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%14 = call i64 @system(i8* %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %36
16: ; preds = %7
%17 = load i32, i32* %4
%18 = add nsw i32 %17, -1
store i32 %18, i32* %4
%19 = icmp eq i32 %17, 0
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = load i8*, i8** %3
%22 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %21)
store i32 -1, i32* %2
br label %41
23: ; preds = %16
%24 = load i8*, i8** %3
%25 = load i32, i32* %4
%26 = sub nsw i32 5, %25
%27 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0), i8* %24, i32 %26)
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%29 = call i32 @memset(i8* %28, i32 0, i32 256)
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%31 = load i8*, i8** %3
%32 = call i32 @snprintf(i8* %30, i32 256, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %31)
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%34 = call i64 @system(i8* %33)
%35 = call i32 @sleep(i32 2)
br label %39
36: ; preds = %7
%37 = load i8*, i8** %3
%38 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %37)
br label %40
39: ; preds = %23
br label %7
40: ; preds = %36
store i32 0, i32* %2
br label %41
41: ; preds = %40, %20
%42 = load i32, i32* %2
ret i32 %42
}

LLVM IR (-O2):
@.str = [19 x i8] c"ifconfig | grep %s\00"
@.str.1 = [34 x i8] c"Ethernet interface %s is not up.\0A\00"
@.str.2 = [49 x i8] c"trying to bring up interface %s, retry %u times\0A\00"
@.str.3 = [15 x i8] c"ifconfig %s up\00"
@.str.4 = [29 x i8] c"Ethernet interface %s is up\0A\00"
define i32 @bring_up_intf(i8* %0) {
%2 = alloca [256 x i8]
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%5 = call i32 @memset(i8* %4, i32 0, i32 256)
%6 = call i32 @snprintf(i8* %4, i32 256, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %0)
%7 = call i64 @system(i8* %4)
%8 = icmp eq i64 %7, 0
br i1 %8, label %28, label %9
9: ; preds = %1
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
br label %11
11: ; preds = %9, %16
%12 = phi i32 [ 5, %9 ], [ %17, %16 ]
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %30
16: ; preds = %11
%17 = add nsw i32 %12, -1
%18 = sub nuw nsw i32 6, %12
%19 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0), i8* %0, i32 %18)
%20 = call i32 @memset(i8* %10, i32 0, i32 256)
%21 = call i32 @snprintf(i8* %10, i32 256, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%22 = call i64 @system(i8* %10)
%23 = call i32 @sleep(i32 2)
%24 = call i32 @memset(i8* %4, i32 0, i32 256)
%25 = call i32 @snprintf(i8* %4, i32 256, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %0)
%26 = call i64 @system(i8* %4)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %11
28: ; preds = %16, %1
%29 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %0)
br label %30
30: ; preds = %14, %28
%31 = phi i32 [ 0, %28 ], [ -1, %14 ]
ret i32 %31
}